Skip to content

Commit

Permalink
libflux/message: rename get_jsonf->unpack
Browse files Browse the repository at this point in the history
Rename flux_msg_get_jsonf() to flux_msg_unpack()
per discussion in flux-framework#1094.

Update unit tests.
  • Loading branch information
garlick committed Jul 10, 2017
1 parent fadf34f commit e53d8af
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/common/libflux/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ int flux_msg_vget_jsonf (const flux_msg_t *cmsg, const char *fmt, va_list ap)
return rc;
}

int flux_msg_get_jsonf (const flux_msg_t *msg, const char *fmt, ...)
int flux_msg_unpack (const flux_msg_t *msg, const char *fmt, ...)
{
va_list ap;
int rc;
Expand Down
4 changes: 2 additions & 2 deletions src/common/libflux/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ bool flux_msg_has_payload (const flux_msg_t *msg);
/* Get/set JSON payload.
* flux_msg_set_json() accepts a NULL json_str (no payload).
* flux_msg_get_json() will set json_str to NULL if there is no payload
* jsonf functions use jansson pack/unpack style arguments for
* pack/unpack functions use jansson pack/unpack style arguments for
* encoding/decoding the JSON object payload directly from/to its members.
*/
int flux_msg_set_json (flux_msg_t *msg, const char *json_str);
int flux_msg_pack (flux_msg_t *msg, const char *fmt, ...);
int flux_msg_vpack (flux_msg_t *msg, const char *fmt, va_list ap);

int flux_msg_get_json (const flux_msg_t *msg, const char **json_str);
int flux_msg_get_jsonf (const flux_msg_t *msg, const char *fmt, ...);
int flux_msg_unpack (const flux_msg_t *msg, const char *fmt, ...);
int flux_msg_vget_jsonf (const flux_msg_t *msg, const char *fmt, va_list ap);

/* Get/set nodeid (request only)
Expand Down
28 changes: 14 additions & 14 deletions src/common/libflux/test/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ void check_payload_json_formatted (void)
ok ((msg = flux_msg_create (FLUX_MSGTYPE_REQUEST)) != NULL,
"flux_msg_create works");
errno = 0;
ok (flux_msg_get_jsonf (msg, "{}") < 0 && errno == EPROTO,
"flux_msg_get_jsonf fails with EPROTO with no payload");
ok (flux_msg_unpack (msg, "{}") < 0 && errno == EPROTO,
"flux_msg_unpack fails with EPROTO with no payload");

errno = 0;
ok (flux_msg_pack (msg, "[i,i,i]", 1,2,3) < 0 && errno == EINVAL,
Expand All @@ -187,8 +187,8 @@ void check_payload_json_formatted (void)
"flux_msg_pack object works");
i = 0;
s = NULL;
ok (flux_msg_get_jsonf (msg, "{s:i, s:s}", "foo", &i, "bar", &s) == 0,
"flux_msg_get_jsonf object works");
ok (flux_msg_unpack (msg, "{s:i, s:s}", "foo", &i, "bar", &s) == 0,
"flux_msg_unpack object works");
ok (i == 42 && s != NULL && !strcmp (s, "baz"),
"decoded content matches encoded content");

Expand All @@ -197,29 +197,29 @@ void check_payload_json_formatted (void)
"flux_msg_pack can replace JSON object payload");
i = 0;
s = NULL;
ok (flux_msg_get_jsonf (msg, "{s:i, s:s}", "foo", &i, "bar", &s) == 0,
"flux_msg_get_jsonf object works");
ok (flux_msg_unpack (msg, "{s:i, s:s}", "foo", &i, "bar", &s) == 0,
"flux_msg_unpack object works");
ok (i == 43 && s != NULL && !strcmp (s, "smurf"),
"decoded content matches new encoded content");

i = 0;
s = NULL;
ok (flux_msg_get_jsonf (msg, "{s:s, s:i}", "bar", &s, "foo", &i) == 0,
"flux_msg_get_jsonf object works out of order");
ok (flux_msg_unpack (msg, "{s:s, s:i}", "bar", &s, "foo", &i) == 0,
"flux_msg_unpack object works out of order");
ok (i == 43 && s != NULL && !strcmp (s, "smurf"),
"decoded content matches new encoded content");

errno = 0;
ok (flux_msg_get_jsonf (msg, NULL) < 0 && errno == EINVAL,
"flux_msg_get_jsonf fails with EINVAL with NULL format");
ok (flux_msg_unpack (msg, NULL) < 0 && errno == EINVAL,
"flux_msg_unpack fails with EINVAL with NULL format");

errno = 0;
ok (flux_msg_get_jsonf (msg, "") < 0 && errno == EINVAL,
"flux_msg_get_jsonf fails with EINVAL with \"\" format");
ok (flux_msg_unpack (msg, "") < 0 && errno == EINVAL,
"flux_msg_unpack fails with EINVAL with \"\" format");

errno = 0;
ok (flux_msg_get_jsonf (msg, "{s:s}", "nope", &s) < 0 && errno == EPROTO,
"flux_msg_get_jsonf fails with EPROTO with nonexistent key");
ok (flux_msg_unpack (msg, "{s:s}", "nope", &s) < 0 && errno == EPROTO,
"flux_msg_unpack fails with EPROTO with nonexistent key");

flux_msg_destroy (msg);
}
Expand Down

0 comments on commit e53d8af

Please sign in to comment.