Skip to content

Commit

Permalink
fix(c): encode b64 arrays with clazz
Browse files Browse the repository at this point in the history
  • Loading branch information
mchitre committed Jul 6, 2021
1 parent bbb3691 commit c6a3b8d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions gateways/c/fjage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1231,24 +1231,29 @@ void fjage_msg_add_bool(fjage_msg_t msg, const char* key, bool value) {
if (s != NULL) sprintf(s, "\"%s\": %s, ", key, value?"true":"false");
}

static void fjage_msg_add_b64(fjage_msg_t msg, const char* key, const char* value, const char* clazz) {
char* s = msg_append(msg, strlen(key)+strlen(clazz)+strlen(value)+32);
if (s != NULL) sprintf(s, "\"%s\": {\"clazz\": \"%s\", \"data\": \"%s\"}, ", key, clazz, value);
}

void fjage_msg_add_byte_array(fjage_msg_t msg, const char* key, uint8_t* value, int len) {
char* s = b64_encode((unsigned char*)value, len);
if (s == NULL) return;
fjage_msg_add_string(msg, key, s);
fjage_msg_add_b64(msg, key, s, "[B");
free(s);
}

void fjage_msg_add_int_array(fjage_msg_t msg, const char* key, int32_t* value, int len) {
char* s = b64_encode((unsigned char*)value, len*sizeof(int32_t));
if (s == NULL) return;
fjage_msg_add_string(msg, key, s);
fjage_msg_add_b64(msg, key, s, "[I");
free(s);
}

void fjage_msg_add_float_array(fjage_msg_t msg, const char* key, float* value, int len) {
char* s = b64_encode((unsigned char*)value, len*sizeof(float));
if (s == NULL) return;
fjage_msg_add_string(msg, key, s);
fjage_msg_add_b64(msg, key, s, "[F");
free(s);
}

Expand Down

0 comments on commit c6a3b8d

Please sign in to comment.