Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
TLV
/
cpp
/
test.cpp
TLV
/
cpp
/
test.cpp
test.cpp 5.95 KB
Copy Edit Raw Blame History
/*
* COPYRIGHT NOTICE
* Copyright (C) 2015, Jhuster, All Rights Reserved
* Author: Jhuster(lujun.hust@gmail.com)
*
* https://github.com/Jhuster/TLV
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License,
* or (at your option) any later version.
*/
#include <iostream>
#include <string>
#include "tlv_box.h"
using namespace tlv;
#define TEST_TYPE_0 0x00
#define TEST_TYPE_1 0x01
#define TEST_TYPE_2 0x02
#define TEST_TYPE_3 0x03
#define TEST_TYPE_4 0x04
#define TEST_TYPE_5 0x05
#define TEST_TYPE_6 0x06
#define TEST_TYPE_7 0x07
#define TEST_TYPE_8 0x08
#define TEST_TYPE_9 0x09
#define TEST_TYPE_a 0x0a
#define TEST_TYPE_b 0x0b
#define TEST_TYPE_c 0x0c
int main(int argc, char const *argv[])
{
TlvBox box;
box.PutNoValue(TEST_TYPE_b);
box.PutBoolValue(TEST_TYPE_0, true);
box.PutCharValue(TEST_TYPE_1, 'x');
box.PutShortValue(TEST_TYPE_2, (short)2);
box.PutIntValue(TEST_TYPE_3, (int)3);
box.PutLongValue(TEST_TYPE_4, (long)4);
box.PutLongLongValue(TEST_TYPE_c, (long long)4);
box.PutFloatValue(TEST_TYPE_5, (float)5.67);
box.PutDoubleValue(TEST_TYPE_6, (double)8.91);
box.PutStringValue(TEST_TYPE_7, (char *)"hello world !");
std::string name = "name";
box.PutStringValue(TEST_TYPE_8, name);
unsigned char array[6] = {1, 2, 3, 4, 5, 6};
box.PutBytesValue(TEST_TYPE_9, array, 6);
if (!box.Serialize()) {
std::cout << "box Serialize Failed !\n";
return -1;
}
std::cout << "box Serialize Success, " << box.GetSerializedBytes() << " bytes \n";
TlvBox boxes;
boxes.PutObjectValue(TEST_TYPE_a, box);
if (!boxes.Serialize()) {
std::cout << "boxes Serialize Failed !\n";
return -1;
}
std::cout << "boxes Serialize Success, " << boxes.GetSerializedBytes() << " bytes \n";
TlvBox parsedBoxes;
if (!parsedBoxes.Parse(boxes.GetSerializedBuffer(), boxes.GetSerializedBytes())) {
std::cout << "boxes Parse Failed !\n";
return -1;
}
std::cout << "boxes Parse Success, " << parsedBoxes.GetSerializedBytes() << " bytes \n";
TlvBox parsedBox;
if (!parsedBoxes.GetObjectValue(TEST_TYPE_a, parsedBox)) {
std::cout << "GetObjectValue Failed !\n";
return -1;
}
std::cout << "box Parse Success, " << parsedBox.GetSerializedBytes() << " bytes \n";
std::vector<int> tlvList;
int numTlvs = parsedBox.GetTLVList(tlvList);
std::cout << "box contains " << numTlvs << " TLVs: \n";
for (int i=0;i<numTlvs; i++)
std::cout << "Tlv " << std::hex << tlvList[i] << "\n";
{
if (!parsedBox.GetNoValue(TEST_TYPE_b)) {
std::cout << "GetNoValue Failed !\n";
return -1;
}
std::cout << "GetNoValue Success " << std::endl;
}
{
bool value;
if (!parsedBox.GetBoolValue(TEST_TYPE_0, value)) {
std::cout << "GetBoolValue Failed !\n";
return -1;
}
std::cout << "GetBoolValue Success " << value << std::endl;
}
{
char value;
if (!parsedBox.GetCharValue(TEST_TYPE_1, value)) {
std::cout << "GetCharValue Failed !\n";
return -1;
}
std::cout << "GetCharValue Success " << value << std::endl;
}
{
short value;
if (!parsedBox.GetShortValue(TEST_TYPE_2, value)) {
std::cout << "GetShortValue Failed !\n";
return -1;
}
std::cout << "GetShortValue Success " << value << std::endl;
}
{
int value;
if (!parsedBox.GetIntValue(TEST_TYPE_3, value)) {
std::cout << "GetIntValue Failed !\n";
return -1;
}
std::cout << "GetIntValue Success " << value << std::endl;
}
{
long value;
if (!parsedBox.GetLongValue(TEST_TYPE_4, value)) {
std::cout << "GetLongValue Failed !\n";
return -1;
}
std::cout << "GetLongValue Success " << value << std::endl;
}
{
long long value;
if (!parsedBox.GetLongLongValue(TEST_TYPE_c, value)) {
std::cout << "GetLongLongValue Failed !\n";
return -1;
}
std::cout << "GetLongLongValue Success " << value << std::endl;
}
{
float value;
if (!parsedBox.GetFloatValue(TEST_TYPE_5, value)) {
std::cout << "GetFloatValue Failed !\n";
return -1;
}
std::cout << "GetFloatValue Success " << value << std::endl;
}
{
double value;
if (!parsedBox.GetDoubleValue(TEST_TYPE_6, value)) {
std::cout << "GetDoubleValue Failed !\n";
return -1;
}
std::cout << "GetDoubleValue Success " << value << std::endl;
}
{
char value[128];
int length = 128;
if (!parsedBox.GetStringValue(TEST_TYPE_7, value, length)) {
std::cout << "GetStringValue Failed !\n";
return -1;
}
std::cout << "GetStringValue Success " << value << std::endl;
}
{
std::string value;
if (!parsedBox.GetStringValue(TEST_TYPE_8, value)) {
std::cout << "GetStringValue Failed !\n";
return -1;
}
std::cout << "GetStringValue Success " << value << std::endl;
}
{
unsigned char value[128];
int length = 128;
if (!parsedBox.GetBytesValue(TEST_TYPE_9, value, length)) {
std::cout << "GetBytesValue Failed !\n";
return -1;
}
std::cout << "GetBytesValue Success ";
for (int i=0; i<length; i++) {
std::cout << (int)value[i] << "--";
}
std::cout << std::endl;
}
return 0;
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Provide some easy-to-use API for TLV encode and decode
Cancel

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mbed/TLV.git
git@gitee.com:mbed/TLV.git
mbed
TLV
TLV
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /