Skip to content

added syntax highlighting #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
added syntax highlighting
  • Loading branch information
nlohmann authored Apr 16, 2018
commit a3533a45ddd13fe98c5475a1f740bc5df9ff50b0
54 changes: 28 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,40 @@

The goal of blob_tree is to bring the heirarchical tree like structure of JSON to the world of binary data.

#include "blob_tree.h"
#include <assert.h>
using namespace std;
int main(int argc, char* argv[])
{
dicroce::blob_tree bt;
```cpp
#include "blob_tree.h"
#include <assert.h>
using namespace std;
int main(int argc, char* argv[])
{
dicroce::blob_tree bt;

vector<uint8_t> b1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
vector<uint8_t> b2 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
vector<uint8_t> b1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
vector<uint8_t> b2 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};

// Create a node called "blobs" and store two blobs ("b1" and "b2") under it.
bt["blobs"]["b1"] = make_pair(b1.size(), &b1[0]); // data is inserted as a pair of pointer and size variables
bt["blobs"]["b2"] = make_pair(b2.size(), &b2[0]);
// Create a node called "blobs" and store two blobs ("b1" and "b2") under it.
bt["blobs"]["b1"] = make_pair(b1.size(), &b1[0]); // data is inserted as a pair of pointer and size variables
bt["blobs"]["b2"] = make_pair(b2.size(), &b2[0]);

vector<uint8_t> b3 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
vector<uint8_t> b4 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
vector<uint8_t> b3 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
vector<uint8_t> b4 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};

// Blobs can also be stored by array indexes.
bt["blobs"]["container"][0] = make_pair(b3.size(), &b3[0]);
bt["blobs"]["container"][1] = make_pair(b4.size(), &b4[0]);
// Blobs can also be stored by array indexes.
bt["blobs"]["container"][0] = make_pair(b3.size(), &b3[0]);
bt["blobs"]["container"][1] = make_pair(b4.size(), &b4[0]);

// serialize() stores the whole blob tree and every added item to a vector
// of bytes.
vector<uint8_t> serialized = dicroce::blob_tree::serialize(bt, 1);
// serialize() stores the whole blob tree and every added item to a vector
// of bytes.
vector<uint8_t> serialized = dicroce::blob_tree::serialize(bt, 1);

uint32_t version;
auto bt2 = dicroce::blob_tree::deserialize(&serialized[0], serialized.size(), version);
uint32_t version;
auto bt2 = dicroce::blob_tree::deserialize(&serialized[0], serialized.size(), version);

// fetching an item from the blob tree...
auto val = bt["blobs"]["b1"].get();
// fetching an item from the blob tree...
auto val = bt["blobs"]["b1"].get();

assert(memcmp(val.second, &b1[0], val.first) == 0);
assert(memcmp(val.second, &b1[0], val.first) == 0);

return 0;
}
return 0;
}
```