Skip to content

Commit

Permalink
📝 clean up and added documentation for #358
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Dec 11, 2016
1 parent fdce38f commit dc6fc3e
Show file tree
Hide file tree
Showing 15 changed files with 665 additions and 114 deletions.
18 changes: 18 additions & 0 deletions doc/examples/from_cbor.cpp
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions doc/examples/from_cbor.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/TDPaxmQ7PsvfWxrs"><b>online</b></a>
4 changes: 4 additions & 0 deletions doc/examples/from_cbor.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"compact": true,
"schema": 0
}
18 changes: 18 additions & 0 deletions doc/examples/from_msgpack.cpp
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions doc/examples/from_msgpack.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/7vRGmLdVcYM7POhE"><b>online</b></a>
4 changes: 4 additions & 0 deletions doc/examples/from_msgpack.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"compact": true,
"schema": 0
}
19 changes: 19 additions & 0 deletions doc/examples/to_cbor.cpp
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions doc/examples/to_cbor.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/UaDbrgZ8OPWaShY8"><b>online</b></a>
1 change: 1 addition & 0 deletions doc/examples/to_cbor.output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xa2 0x67 0x63 0x6f 0x6d 0x70 0x61 0x63 0x74 0xf5 0x66 0x73 0x63 0x68 0x65 0x6d 0x61 0x00
19 changes: 19 additions & 0 deletions doc/examples/to_msgpack.cpp
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions doc/examples/to_msgpack.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/jvaU8GEfAusb5dKf"><b>online</b></a>
1 change: 1 addition & 0 deletions doc/examples/to_msgpack.output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x82 0xa7 0x63 0x6f 0x6d 0x70 0x61 0x63 0x74 0xc3 0xa6 0x73 0x63 0x68 0x65 0x6d 0x61 0x00
Loading

0 comments on commit dc6fc3e

Please sign in to comment.