📝 clean up and added documentation for #358
This commit is contained in:
parent
fdce38fa79
commit
dc6fc3e079
15 changed files with 665 additions and 114 deletions
18
doc/examples/from_cbor.cpp
Normal file
18
doc/examples/from_cbor.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include <json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create byte vector
|
||||
std::vector<uint8_t> v = {0xa2, 0x67, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63,
|
||||
0x74, 0xf5, 0x66, 0x73, 0x63, 0x68, 0x65, 0x6d,
|
||||
0x61, 0x00
|
||||
};
|
||||
|
||||
// deserialize it with CBOR
|
||||
json j = json::from_cbor(v);
|
||||
|
||||
// print the deserialized JSON value
|
||||
std::cout << std::setw(2) << j << std::endl;
|
||||
}
|
||||
1
doc/examples/from_cbor.link
Normal file
1
doc/examples/from_cbor.link
Normal file
|
|
@ -0,0 +1 @@
|
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/TDPaxmQ7PsvfWxrs"><b>online</b></a>
|
||||
4
doc/examples/from_cbor.output
Normal file
4
doc/examples/from_cbor.output
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"compact": true,
|
||||
"schema": 0
|
||||
}
|
||||
18
doc/examples/from_msgpack.cpp
Normal file
18
doc/examples/from_msgpack.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include <json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create byte vector
|
||||
std::vector<uint8_t> v = {0x82, 0xa7, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63,
|
||||
0x74, 0xc3, 0xa6, 0x73, 0x63, 0x68, 0x65, 0x6d,
|
||||
0x61, 0x00
|
||||
};
|
||||
|
||||
// deserialize it with MessagePack
|
||||
json j = json::from_msgpack(v);
|
||||
|
||||
// print the deserialized JSON value
|
||||
std::cout << std::setw(2) << j << std::endl;
|
||||
}
|
||||
1
doc/examples/from_msgpack.link
Normal file
1
doc/examples/from_msgpack.link
Normal file
|
|
@ -0,0 +1 @@
|
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/7vRGmLdVcYM7POhE"><b>online</b></a>
|
||||
4
doc/examples/from_msgpack.output
Normal file
4
doc/examples/from_msgpack.output
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"compact": true,
|
||||
"schema": 0
|
||||
}
|
||||
19
doc/examples/to_cbor.cpp
Normal file
19
doc/examples/to_cbor.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include <json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create a JSON value
|
||||
json j = R"({"compact": true, "schema": 0})"_json;
|
||||
|
||||
// serialize it to CBOR
|
||||
std::vector<uint8_t> v = json::to_cbor(j);
|
||||
|
||||
// print the vector content
|
||||
for (auto& byte : v)
|
||||
{
|
||||
std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << (int)byte << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
1
doc/examples/to_cbor.link
Normal file
1
doc/examples/to_cbor.link
Normal file
|
|
@ -0,0 +1 @@
|
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/UaDbrgZ8OPWaShY8"><b>online</b></a>
|
||||
1
doc/examples/to_cbor.output
Normal file
1
doc/examples/to_cbor.output
Normal file
|
|
@ -0,0 +1 @@
|
|||
0xa2 0x67 0x63 0x6f 0x6d 0x70 0x61 0x63 0x74 0xf5 0x66 0x73 0x63 0x68 0x65 0x6d 0x61 0x00
|
||||
19
doc/examples/to_msgpack.cpp
Normal file
19
doc/examples/to_msgpack.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include <json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create a JSON value
|
||||
json j = R"({"compact": true, "schema": 0})"_json;
|
||||
|
||||
// serialize it to MessagePack
|
||||
std::vector<uint8_t> v = json::to_msgpack(j);
|
||||
|
||||
// print the vector content
|
||||
for (auto& byte : v)
|
||||
{
|
||||
std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << (int)byte << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
1
doc/examples/to_msgpack.link
Normal file
1
doc/examples/to_msgpack.link
Normal file
|
|
@ -0,0 +1 @@
|
|||
<a target="_blank" href="http://melpon.org/wandbox/permlink/jvaU8GEfAusb5dKf"><b>online</b></a>
|
||||
1
doc/examples/to_msgpack.output
Normal file
1
doc/examples/to_msgpack.output
Normal file
|
|
@ -0,0 +1 @@
|
|||
0x82 0xa7 0x63 0x6f 0x6d 0x70 0x61 0x63 0x74 0xc3 0xa6 0x73 0x63 0x68 0x65 0x6d 0x61 0x00
|
||||
Loading…
Add table
Add a link
Reference in a new issue