博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
我的开源项目:一种TLV编解码器的实现
阅读量:7196 次
发布时间:2019-06-29

本文共 1924 字,大约阅读时间需要 6 分钟。

一个TLV对象示例如下:

 

 

多个TLV对象可以连接起来,组成一个大的buffer:

一个TLV对象内部也可以嵌套另一个TLV对象:

我希望能提供一套API接口(C/C++/Java/其他语言),可以方便地完成TLV格式的编码和解码,项目地址如下所示:

其中,C++版本已经实现(更新:C/Java/Android版本也均已实现),介绍如下:

1. TLV编码的接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//put one TLV box
bool 
PutBoolValue(
int 
type,
bool 
value);
bool 
PutCharValue(
int 
type,
char 
value);
bool 
PutShortValue(
int 
type,
short 
value);
bool 
PutIntValue(
int 
type,
int 
value);
bool 
PutLongValue(
int 
type,
long 
value);
bool 
PutLongLongValue(
int 
type,
long 
long 
value);
bool 
PutFloatValue(
int 
type,
float 
value);
bool 
PutDoubleValue(
int 
type,
double 
value);
bool 
PutStringValue(
int 
type,
char 
*value);
bool 
PutStringValue(
int 
type,
const 
std::string &value);
bool 
PutBytesValue(
int 
type,unsigned 
char 
*value,
int 
length);
bool 
PutObjectValue(
int 
type,
const 
TlvBox& value);          
 
//do encode
bool 
Serialize(); 
 
//access encoded buffer and length
unsigned 
char 
* GetSerializedBuffer() 
const
;
int 
GetSerializedBytes() 
const
;

2. TLV解码的接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//do decode
bool 
Parse(
const 
unsigned 
char 
*buffer,
int 
buffersize); 
 
//get one TLV box
bool 
GetBoolValue(
int 
type,
bool 
&value) 
const
;
bool 
GetCharValue(
int 
type,
char 
&value) 
const
;
bool 
GetShortValue(
int 
type,
short 
&value) 
const
;
bool 
GetIntValue(
int 
type,
int 
&value) 
const
;
bool 
GetLongValue(
int 
type,
long 
&value) 
const
;
bool 
GetLongLongValue(
int 
type,
long 
long 
&value) 
const
;
bool 
GetFloatValue(
int 
type,
float 
&value) 
const
;
bool 
GetDoubleValue(
int 
type,
double 
&value) 
const
;
bool 
GetStringValue(
int 
type,
char 
*value,
int 
&length) 
const
;
bool 
GetStringValue(
int 
type,std::string &value) 
const
;
bool 
GetBytesValue(
int 
type,unsigned 
char 
*value,
int 
&length) 
const
;
bool 
GetBytesValuePtr(
int 
type,unsigned 
char 
**value,
int 
&length) 
const
;
bool 
GetObjectValue(
int 
type,TlvBox& value) 
const
;
本文转自 Jhuster 51CTO博客,原文链接:http://blog.51cto.com/ticktick/1719378,如需转载请自行联系原作者
你可能感兴趣的文章
Oracle一些demo级function
查看>>
bootstrap datepicker 日历插件
查看>>
OpenService 失败5:拒绝访问
查看>>
查看硬件信息几种方法
查看>>
Hibernate的抓取策略
查看>>
如何备考美国项目管理协会的PMP认证考试
查看>>
Spring动态创建数据源,再动态切换
查看>>
版本号转换
查看>>
我的友情链接
查看>>
IT公司软件工程师薪水排名
查看>>
获得及操作基类的方法
查看>>
Mysql安装说明
查看>>
互联网公司如何做危机公关
查看>>
学生信息管理系统架构设计
查看>>
Spring Boot(2):SpringBootApplication注解
查看>>
我的友情链接
查看>>
Apache如何每天生成独立日志文件(access_log和error_log)
查看>>
用命令行netsh修改windows的ip、网关、dns
查看>>
错误;找不到或无法加载主类 com.sun.tools.javac.main的解决方案
查看>>
scale the service in the swarm
查看>>