Skip to content

Commit

Permalink
Feat: new mpack to sds functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Jun 24, 2024
1 parent f7b0fea commit b4abf20
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lib/mpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,25 @@ void log_mpack_write_error(mpack_writer_t *writer, mpack_error_t error) {
(void) writer;
MYMPD_LOG_ERROR("default", "mpack error: %s", mpack_error_to_string(error));
}

/**
* Creates a sds string from a mpack str
* @param node node to get the key from
* @param key key to get
* @return newly allocated sds string
*/
sds mpackstr_sds(mpack_node_t node, const char *key) {
mpack_node_t data = mpack_node_map_cstr(node, key);
return sdsnewlen(mpack_node_str(data), mpack_node_data_len(data));
}

/**
* Appends a mpack str to a sds string
* @param node node to get the key from
* @param key key to get
* @return newly allocated sds string
*/
sds mpackstr_sdscat(sds s, mpack_node_t node, const char *key) {
mpack_node_t data = mpack_node_map_cstr(node, key);
return sdscatlen(s, mpack_node_str(data), mpack_node_data_len(data));
}
4 changes: 4 additions & 0 deletions src/lib/mpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
#define MYMPD_MPACK_H

#include "dist/mpack/mpack.h"
#include "dist/sds/sds.h"

void log_mpack_node_error(mpack_tree_t *tree, mpack_error_t error);
void log_mpack_write_error(mpack_writer_t *writer, mpack_error_t error);

sds mpackstr_sds(mpack_node_t node, const char *key);
sds mpackstr_sdscat(sds s, mpack_node_t node, const char *key);

#endif

0 comments on commit b4abf20

Please sign in to comment.