2017-04-15 15:44:19 +00:00
|
|
|
#ifndef __PROTOBUF_H__
|
|
|
|
#define __PROTOBUF_H__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2017-04-27 17:18:57 +00:00
|
|
|
#define PB_HEADER_LEN 9
|
|
|
|
|
2017-04-15 15:44:19 +00:00
|
|
|
typedef struct {
|
2017-04-16 15:37:39 +00:00
|
|
|
uint8_t buf[128];
|
|
|
|
uint32_t pos;
|
|
|
|
uint32_t len;
|
2017-04-15 15:44:19 +00:00
|
|
|
} PB_CTX;
|
|
|
|
|
|
|
|
void pb_start(PB_CTX *ctx, uint16_t msg_id);
|
2017-04-16 15:37:39 +00:00
|
|
|
void pb_end(PB_CTX *ctx);
|
2017-04-15 15:44:19 +00:00
|
|
|
|
2017-04-16 15:37:39 +00:00
|
|
|
void pb_add_bool(PB_CTX *ctx, uint32_t field_number, bool val);
|
2017-05-02 17:49:56 +00:00
|
|
|
void pb_add_bytes(PB_CTX *ctx, uint32_t field_number, const uint8_t *val, uint32_t len);
|
2017-04-16 15:37:39 +00:00
|
|
|
void pb_add_string(PB_CTX *ctx, uint32_t field_number, const char *val);
|
|
|
|
void pb_add_varint(PB_CTX *ctx, uint32_t field_number, uint32_t val);
|
2017-04-15 15:44:19 +00:00
|
|
|
|
2017-04-27 13:32:25 +00:00
|
|
|
bool pb_parse_header(const uint8_t *buf, uint16_t *msg_id, uint32_t *msg_size);
|
2017-04-27 17:18:57 +00:00
|
|
|
uint32_t pb_read_varint(const uint8_t *buf, uint32_t *num);
|
2017-04-27 13:32:25 +00:00
|
|
|
|
2017-04-15 15:44:19 +00:00
|
|
|
#endif
|