mirror of
https://github.com/vale981/libblobpack
synced 2025-03-05 18:01:41 -05:00
avr port
This commit is contained in:
parent
1250439e71
commit
4b3b52eed3
4 changed files with 13 additions and 7 deletions
|
@ -213,7 +213,7 @@ blob_offset_t blob_open_array(struct blob *buf){
|
||||||
}
|
}
|
||||||
|
|
||||||
void blob_close_array(struct blob *buf, blob_offset_t offset){
|
void blob_close_array(struct blob *buf, blob_offset_t offset){
|
||||||
if((int)offset > blob_size(buf)) return;
|
if((long)offset > (long)blob_size(buf)) return;
|
||||||
struct blob_field *attr = blob_offset_to_attr(buf, offset);
|
struct blob_field *attr = blob_offset_to_attr(buf, offset);
|
||||||
int len = (buf->buf + blob_field_raw_len(blob_head(buf))) - (void*)attr;
|
int len = (buf->buf + blob_field_raw_len(blob_head(buf))) - (void*)attr;
|
||||||
blob_field_set_raw_len(attr, len);
|
blob_field_set_raw_len(attr, len);
|
||||||
|
@ -225,7 +225,7 @@ blob_offset_t blob_open_table(struct blob *buf){
|
||||||
}
|
}
|
||||||
|
|
||||||
void blob_close_table(struct blob *buf, blob_offset_t offset){
|
void blob_close_table(struct blob *buf, blob_offset_t offset){
|
||||||
if((int)offset > blob_size(buf)) return;
|
if((long)offset > (long)blob_size(buf)) return;
|
||||||
struct blob_field *attr = blob_offset_to_attr(buf, offset);
|
struct blob_field *attr = blob_offset_to_attr(buf, offset);
|
||||||
int len = (buf->buf + blob_field_raw_len(blob_head(buf))) - (void*)attr;
|
int len = (buf->buf + blob_field_raw_len(blob_head(buf))) - (void*)attr;
|
||||||
blob_field_set_raw_len(attr, len);
|
blob_field_set_raw_len(attr, len);
|
||||||
|
|
|
@ -81,7 +81,11 @@ static inline struct blob_field *blob_head(struct blob *self){
|
||||||
//! returns size of the whole buffer (including header element and padding)
|
//! returns size of the whole buffer (including header element and padding)
|
||||||
static inline uint32_t blob_size(struct blob *self){ return blob_field_raw_pad_len(blob_head(self)); }
|
static inline uint32_t blob_size(struct blob *self){ return blob_field_raw_pad_len(blob_head(self)); }
|
||||||
|
|
||||||
|
#ifdef __AVR
|
||||||
|
typedef uint16_t blob_offset_t;
|
||||||
|
#else
|
||||||
typedef void* blob_offset_t;
|
typedef void* blob_offset_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
/********************************
|
/********************************
|
||||||
** NESTED ELEMENTS
|
** NESTED ELEMENTS
|
||||||
|
|
|
@ -239,10 +239,10 @@ static void blob_format_element(struct strbuf *s, struct blob_field *attr, bool
|
||||||
sprintf(buf, "%d", be16_to_cpu(*(uint16_t *)data));
|
sprintf(buf, "%d", be16_to_cpu(*(uint16_t *)data));
|
||||||
break;
|
break;
|
||||||
case BLOB_FIELD_INT32:
|
case BLOB_FIELD_INT32:
|
||||||
sprintf(buf, "%lu", (int32_t) be32_to_cpu(*(uint32_t *)data));
|
sprintf(buf, "%d", (int) be32_to_cpu(*(uint32_t *)data));
|
||||||
break;
|
break;
|
||||||
case BLOB_FIELD_INT64:
|
case BLOB_FIELD_INT64:
|
||||||
sprintf(buf, "%llu", (int64_t) be64_to_cpu(*(uint64_t *)data));
|
sprintf(buf, "%lld", (long long int) be64_to_cpu(*(uint64_t *)data));
|
||||||
break;
|
break;
|
||||||
case BLOB_FIELD_FLOAT32:
|
case BLOB_FIELD_FLOAT32:
|
||||||
sprintf(buf, "%f", (double) unpack754_32(be32_to_cpu(*(uint32_t*)data)));
|
sprintf(buf, "%f", (double) unpack754_32(be32_to_cpu(*(uint32_t*)data)));
|
||||||
|
|
|
@ -85,12 +85,12 @@ JSOBJ Object_newNull(void *prv){
|
||||||
|
|
||||||
JSOBJ Object_newObject(void *prv){
|
JSOBJ Object_newObject(void *prv){
|
||||||
DEBUG("new object\n");
|
DEBUG("new object\n");
|
||||||
return blob_open_table(prv);
|
return (JSOBJ)blob_open_table(prv);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSOBJ Object_newArray(void *prv){
|
JSOBJ Object_newArray(void *prv){
|
||||||
DEBUG("new array\n");
|
DEBUG("new array\n");
|
||||||
return blob_open_array(prv);
|
return (JSOBJ)blob_open_array(prv);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSOBJ Object_newInteger(void *prv, JSINT32 value){
|
JSOBJ Object_newInteger(void *prv, JSINT32 value){
|
||||||
|
@ -116,7 +116,7 @@ JSOBJ Object_newDouble(void *prv, double value){
|
||||||
static void Object_releaseObject(void *prv, JSOBJ obj){
|
static void Object_releaseObject(void *prv, JSOBJ obj){
|
||||||
DEBUG("close array\n");
|
DEBUG("close array\n");
|
||||||
// with blobs close_table and close_array is the same function
|
// with blobs close_table and close_array is the same function
|
||||||
blob_close_table(prv, obj);
|
blob_close_table(prv, (blob_offset_t)obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *Object_Malloc(size_t size){
|
static void *Object_Malloc(size_t size){
|
||||||
|
@ -186,6 +186,8 @@ bool blob_init_from_json(struct blob *self, const char *json){
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
bool blob_put_json_from_file(struct blob *self, const char *file){
|
bool blob_put_json_from_file(struct blob *self, const char *file){
|
||||||
// this is a rather simplistic approach where we just load the whole file into memory and then parse the buffer.
|
// this is a rather simplistic approach where we just load the whole file into memory and then parse the buffer.
|
||||||
// there can probably be better ways where we parse data in place..
|
// there can probably be better ways where we parse data in place..
|
||||||
|
|
Loading…
Add table
Reference in a new issue