mirror of
https://github.com/vale981/libblobpack
synced 2025-03-04 17:31:42 -05:00
small update to docs and blob json formatting methods..
This commit is contained in:
parent
54e41c0c44
commit
a9f575b267
4 changed files with 52 additions and 4 deletions
24
README.md
24
README.md
|
@ -8,7 +8,7 @@ The blobs are packed in platform independent format so you can use blobpack to
|
|||
pack data on one platform and then unpack it on a different one regardless of
|
||||
it's endianness.
|
||||
|
||||
Binary Format
|
||||
Data Types
|
||||
-------------
|
||||
|
||||
Blobpack API shall be agnostic of actual packing implementation and shall
|
||||
|
@ -20,6 +20,28 @@ present the user with ability to pack following types:
|
|||
- array: an aggregation of any number of fields of any type
|
||||
- table: an aggregation of any number of fields where each element is a pair of string and any other type
|
||||
|
||||
Validation
|
||||
----------
|
||||
|
||||
Validation is done using a validation expression that represents the blob structure.
|
||||
|
||||
Example:
|
||||
siia[sv] would match a blob like this [string, int, int, array, array of string value pairs ]
|
||||
|
||||
Valid elements are:
|
||||
|
||||
[ - open nested expression that describes an array
|
||||
] - close nested array
|
||||
{ - open nested expression that describes a table
|
||||
} - close nested table
|
||||
i - an integer
|
||||
f - a floating point number
|
||||
s - a string
|
||||
t - an arbitrary table (don't care about content)
|
||||
a - an arbitrary array (don't care about content)
|
||||
|
||||
Binary Format
|
||||
-------------
|
||||
The binary format shall automatically find the smallest possible wire type to
|
||||
pack the above as and the unpacking function shall read the correct type (which
|
||||
can be smaller) and unpack it into a long long int which is returned to the
|
||||
|
|
19
blob_field.c
19
blob_field.c
|
@ -323,7 +323,24 @@ bool _blob_field_validate(struct blob_field *attr, const char *signature, const
|
|||
continue;
|
||||
break;
|
||||
case 'i':
|
||||
if(blob_field_type(field) != BLOB_FIELD_INT32 && blob_field_type(field) != BLOB_FIELD_INT8) return false;
|
||||
switch(blob_field_type(field)){
|
||||
case BLOB_FIELD_INT8:
|
||||
case BLOB_FIELD_INT16:
|
||||
case BLOB_FIELD_INT32:
|
||||
case BLOB_FIELD_INT64:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
switch(blob_field_type(field)){
|
||||
case BLOB_FIELD_FLOAT32:
|
||||
case BLOB_FIELD_FLOAT64:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
if(blob_field_type(field) != BLOB_FIELD_STRING) return false;
|
||||
|
|
12
blob_json.c
12
blob_json.c
|
@ -341,10 +341,18 @@ char *blob_format_json_indent(struct blob_field *attr, bool list, int indent){
|
|||
return blob_format_json_with_cb(attr, list, NULL, NULL, indent);
|
||||
}
|
||||
|
||||
void blob_field_dump_json(struct blob_field *self){
|
||||
static void _blob_field_dump_json(struct blob_field *self, int indent){
|
||||
assert(self);
|
||||
char *json = blob_format_json_indent(self, true, 1);
|
||||
char *json = blob_format_json_indent(self, true, indent);
|
||||
printf("%s\n", json);
|
||||
free(json);
|
||||
}
|
||||
|
||||
void blob_field_dump_json(struct blob_field *self){
|
||||
_blob_field_dump_json(self, -1);
|
||||
}
|
||||
|
||||
void blob_field_dump_json_pretty(struct blob_field *self){
|
||||
_blob_field_dump_json(self, 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,5 +30,6 @@ char *blob_format_json(struct blob_field *attr, bool list);
|
|||
char *blob_format_json_indent(struct blob_field *attr, bool list, int indent);
|
||||
|
||||
void blob_field_dump_json(struct blob_field *self);
|
||||
void blob_field_dump_json_pretty(struct blob_field *self);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue