提交 734ff3f8 编写于 作者: H Hongze Cheng

refact

上级 a04f78c7
......@@ -23,13 +23,6 @@
extern "C" {
#endif
typedef struct {
td_endian_t endian;
uint8_t* data;
int32_t size;
int32_t pos;
} SEncoder, SDecoder;
#define tPut(TYPE, BUF, VAL) ((TYPE*)(BUF))[0] = (VAL)
#define tGet(TYPE, BUF, VAL) (VAL) = ((TYPE*)(BUF))[0]
......@@ -57,6 +50,13 @@ typedef struct {
#define tRGet32 tRPut32
#define tRGet64 tRPut64
typedef struct {
td_endian_t endian;
uint8_t* data;
int32_t size;
int32_t pos;
} SEncoder, SDecoder;
#define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos)
#define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE))
#define TD_CHECK_CODER_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE))
......
......@@ -56,8 +56,12 @@ void tCoderClear(SCoder* pCoder) {
}
int tStartEncode(SCoder* pCoder) {
struct SCoderNode* pNode;
if (pCoder->data) {
struct SCoderNode* pNode = malloc(sizeof(*pNode));
if (pCoder->size - pCoder->pos < sizeof(int32_t)) return -1;
pNode = malloc(sizeof(*pNode));
if (pNode == NULL) return -1;
pNode->data = pCoder->data;
......@@ -97,11 +101,11 @@ int tStartDecode(SCoder* pCoder) {
int32_t size;
struct SCoderNode* pNode;
// TODO: if (tDecodeI32(pCoder, &size) < 0) return -1;
pNode = malloc(sizeof(*pNode));
if (pNode == NULL) return -1;
// TODO: tDecodeI32(pCoder, &size);
pNode->data = pCoder->data;
pNode->pos = pCoder->pos;
pNode->size = pCoder->size;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册