Commit ddc71966 authored by DEPRECATED (Jonathan Mace) (Use @JonathanMace instead)'s avatar DEPRECATED (Jonathan Mace) (Use @JonathanMace instead)
Browse files

Add some convenience string serialization methods:

parent befbc2f5
......@@ -5,6 +5,7 @@
#include <cstdint>
#include <cstddef>
#include <vector>
#include <string>
/*
......@@ -44,9 +45,11 @@ struct Baggage {
static Baggage merge(Baggage& a, Baggage& b);
// Serialize this baggage, as defined in the Brown Tracing Plane (length-prefix each atom in order)
std::string str();
std::vector<uint8_t> serialize();
// Deserialize a serialized baggage instance, as defined in the Brown Tracing Plane
static Baggage deserialize(std::string bytes);
static Baggage deserialize(std::vector<uint8_t> bytes);
friend std::ostream& operator<< ( std::ostream& os, const Baggage& baggage );
......
......@@ -4,6 +4,7 @@
#include <cstdint>
#include <cstddef>
#include <vector>
#include <string>
std::vector<uint8_t> encodeVarint(uint64_t x) {
std::vector<uint8_t> s;
......@@ -98,6 +99,16 @@ std::vector<uint8_t> Baggage::serialize() {
return bytes;
}
std::string Baggage::str() {
std::vector<uint8_t> bytes = this->serialize();
return std::string(bytes.begin(), bytes.end());
}
Baggage Baggage::deserialize(std::string bytes) {
std::vector<uint8_t> bytev(bytes.begin(), bytes.end());
return Baggage::deserialize(bytev);
}
Baggage Baggage::deserialize(std::vector<uint8_t> bytes) {
Baggage baggage;
unsigned n = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment