more
This commit is contained in:
parent
070562ae57
commit
a32fa005a8
|
@ -16,7 +16,7 @@
|
||||||
#ifndef _TD_UTIL_ENCODE_H_
|
#ifndef _TD_UTIL_ENCODE_H_
|
||||||
#define _TD_UTIL_ENCODE_H_
|
#define _TD_UTIL_ENCODE_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "tcoding.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -162,11 +162,11 @@ static FORCE_INLINE int tEncodeU64(SEncoder* pEncoder, uint64_t val) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeI32(SEncoder* pEncoder, int32_t val) {
|
static FORCE_INLINE int tEncodeI64(SEncoder* pEncoder, int64_t val) {
|
||||||
if (pEncoder->data) {
|
if (pEncoder->data) {
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
||||||
if (TD_RT_ENDIAN() == pEncoder->endian) {
|
if (TD_RT_ENDIAN() == pEncoder->endian) {
|
||||||
tPut(int32_t, TD_CODER_CURRENT(pEncoder), val);
|
tPut(int64_t, TD_CODER_CURRENT(pEncoder), val);
|
||||||
} else {
|
} else {
|
||||||
tRPut64(TD_CODER_CURRENT(pEncoder), &val);
|
tRPut64(TD_CODER_CURRENT(pEncoder), &val);
|
||||||
}
|
}
|
||||||
|
@ -175,6 +175,44 @@ static FORCE_INLINE int tEncodeI32(SEncoder* pEncoder, int32_t val) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int tEncodeU16v(SEncoder* pEncoder, uint16_t val) {
|
||||||
|
int64_t i = 0;
|
||||||
|
while (val >= ENCODE_LIMIT) {
|
||||||
|
if (pEncoder->data) {
|
||||||
|
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1;
|
||||||
|
TD_CODER_CURRENT(pEncoder)[i] = (uint8_t)(val | ENCODE_LIMIT)
|
||||||
|
}
|
||||||
|
|
||||||
|
val >>= 7;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEncoder->data) {
|
||||||
|
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1;
|
||||||
|
TD_CODER_CURRENT(pEncoder)[i] = (uint8_t)val;
|
||||||
|
}
|
||||||
|
|
||||||
|
TD_CODER_MOVE_POS(pEncoder, i + 1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int tEncodeI16v(SEncoder* pEncoder, int16_t val) { return tEncodeU16v(pEncoder, ZIGZAGE(val)); }
|
||||||
|
|
||||||
|
static FORCE_INLINE int tEncodeU32v(SEncoder* pEncoder, uint32_t val) {
|
||||||
|
// TODO
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int tEncodeI32v(SEncoder* pEncoder, int32_t val) { return tEncodeU32v(pEncoder, ZIGZAGE(val)); }
|
||||||
|
|
||||||
|
static FORCE_INLINE int tEncodeU64v(SEncoder* pEncoder, uint64_t val) {
|
||||||
|
// TODO
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int tEncodeI64v(SEncoder* pEncoder, int64_t val) { return tEncodeU64v(pEncoder, ZIGZAGE(val)); }
|
||||||
|
|
||||||
/* ------------------------ FOR DECODER ------------------------ */
|
/* ------------------------ FOR DECODER ------------------------ */
|
||||||
static FORCE_INLINE void tInitDecoder(SDecoder* pDecoder, td_endian_t endian, const uint8_t* data, int64_t size) {
|
static FORCE_INLINE void tInitDecoder(SDecoder* pDecoder, td_endian_t endian, const uint8_t* data, int64_t size) {
|
||||||
ASSERT(!TD_IS_NULL(data));
|
ASSERT(!TD_IS_NULL(data));
|
||||||
|
|
Loading…
Reference in New Issue