gateway-old/protobuf.c

33 lines
797 B
C
Raw Normal View History

2020-02-17 14:17:23 -08:00
#include "message.pb-c.h"
#include "protobuf.h"
#include <stdlib.h>
void* _allocator_alloc(void*, size_t count) {
return malloc(count);
}
void _allocator_free(void*, void* data) {
free(data);
}
static ProtobufCAllocator malloc_allocator = {
_allocator_alloc, _allocator_free, NULL
};
void encode_update(double x, double y, uint8_t* buffer) {
Fenceless__Coordinate coord;
Fenceless__CollarResponse response;
fenceless__coordinate__init(&coord);
coord.x = x;
coord.y = y;
fenceless__collar_response__init(&response);
response.loc = &coord;
fenceless__collar_response__pack(&response, buffer);
}
Fenceless__CollarResponse* decode_update(size_t len, uint8_t* buffer) {
return fenceless__collar_response__unpack(&malloc_allocator, len, buffer);
}