mirror of
https://github.com/vale981/libblobpack
synced 2025-03-05 09:51:42 -05:00
add ability to dump into json and to forcibly set type
This commit is contained in:
parent
ef73c55efc
commit
1f43c831fd
3 changed files with 12 additions and 7 deletions
7
blob.c
7
blob.c
|
@ -239,13 +239,6 @@ struct blob_attr *blob_buf_put_attr(struct blob_buf *buf, struct blob_attr *attr
|
|||
}
|
||||
|
||||
static void __attribute__((unused)) _blob_attr_dump(struct blob_attr *node, int indent){
|
||||
/*if(blob_attr_type(node) == BLOB_ATTR_ARRAY || blob_attr_type(node) == BLOB_ATTR_TABLE){
|
||||
printf(">>\n");
|
||||
_blob_attr_dump(self, attr, blob_attr_data(attr));
|
||||
printf("<<\n");
|
||||
return;
|
||||
}*/
|
||||
|
||||
static const char *names[] = {
|
||||
[BLOB_ATTR_ROOT] = "BLOB_ATTR_ROOT",
|
||||
//[BLOB_ATTR_NESTED] = "BLOB_ATTR_NESTED",
|
||||
|
|
|
@ -50,6 +50,12 @@ static inline unsigned int blob_attr_type(const struct blob_attr *attr){
|
|||
return id;
|
||||
}
|
||||
|
||||
static inline void blob_attr_set_type(struct blob_attr *self, int type){
|
||||
int id_len = be32_to_cpu(self->id_len);
|
||||
id_len = (id_len & ~BLOB_ATTR_ID_MASK) | (type << BLOB_ATTR_ID_SHIFT);
|
||||
self->id_len = cpu_to_be32(id_len);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
blob_attr_has_name(const struct blob_attr *attr){
|
||||
if(!attr) return false;
|
||||
|
|
|
@ -40,4 +40,10 @@ static inline char *blob_buf_format_json_indent(struct blob_attr *attr, bool lis
|
|||
return blob_buf_format_json_with_cb(attr, list, NULL, NULL, indent);
|
||||
}
|
||||
|
||||
static inline void blob_attr_dump_json(struct blob_attr *self){
|
||||
char *json = blob_buf_format_json(self, true);
|
||||
printf("%s\n", json);
|
||||
free(json);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue