Commit 962d4064 authored by Nikias Bassen's avatar Nikias Bassen

bplist: Improve writing of integer nodes

parent 458341fc
...@@ -837,36 +837,27 @@ static void serialize_plist(node_t* node, void* data) ...@@ -837,36 +837,27 @@ static void serialize_plist(node_t* node, void* data)
static void write_int(bytearray_t * bplist, uint64_t val) static void write_int(bytearray_t * bplist, uint64_t val)
{ {
uint64_t size = get_needed_bytes(val); int size = get_needed_bytes(val);
uint8_t *buff = NULL; uint8_t sz;
//do not write 3bytes int node //do not write 3bytes int node
if (size == 3) if (size == 3)
size++; size++;
sz = BPLIST_UINT | Log2(size);
#ifdef __BIG_ENDIAN__ val = be64toh(val);
val = val << ((sizeof(uint64_t) - size) * 8); byte_array_append(bplist, &sz, 1);
#endif byte_array_append(bplist, (uint8_t*)&val + (8-size), size);
buff = (uint8_t *) malloc(sizeof(uint8_t) + size);
buff[0] = BPLIST_UINT | Log2(size);
memcpy(buff + 1, &val, size);
byte_convert(buff + 1, size);
byte_array_append(bplist, buff, sizeof(uint8_t) + size);
free(buff);
} }
static void write_uint(bytearray_t * bplist, uint64_t val) static void write_uint(bytearray_t * bplist, uint64_t val)
{ {
uint64_t size = 16; uint8_t sz = BPLIST_UINT | 4;
uint8_t *buff = NULL; uint64_t zero = 0;
buff = (uint8_t *) malloc(sizeof(uint8_t) + size); val = be64toh(val);
buff[0] = BPLIST_UINT | 4; byte_array_append(bplist, &sz, 1);
memset(buff + 1, '\0', 8); byte_array_append(bplist, &zero, sizeof(uint64_t));
memcpy(buff + 9, &val, 8); byte_array_append(bplist, &val, sizeof(uint64_t));
byte_convert(buff + 9, 8);
byte_array_append(bplist, buff, sizeof(uint8_t) + size);
free(buff);
} }
static void write_real(bytearray_t * bplist, double val) static void write_real(bytearray_t * bplist, double val)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment