add ability to dump into json and to forcibly set type

This commit is contained in:
Martin Schröder 2015-12-17 16:56:20 +01:00
parent ef73c55efc
commit 1f43c831fd
3 changed files with 12 additions and 7 deletions

7
blob.c
View file

@ -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",

View file

@ -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;

View file

@ -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