Go to the documentation of this file.
24 #ifndef GOBY_MIDDLEWARE_MARSHALLING_JSON_H
25 #define GOBY_MIDDLEWARE_MARSHALLING_JSON_H
27 #include <boost/type_index.hpp>
42 auto bson = nlohmann::json::to_bson(
msg);
43 std::vector<char> bytes(bson.begin(), bson.end());
49 return "nlohmann::json";
52 template <
typename CharIterator>
53 static std::shared_ptr<nlohmann::json>
parse(CharIterator bytes_begin, CharIterator bytes_end,
54 CharIterator& actual_end,
57 actual_end = bytes_end;
58 return std::make_shared<nlohmann::json>(nlohmann::json::from_bson(bytes_begin, bytes_end));
62 template <
typename T,
class Enable =
void> constexpr
const char*
json_type_name()
64 return T::goby_json_type;
76 static std::string
type_name(
const T& t = T()) {
return json_type_name<T>(); }
78 template <
typename CharIterator>
79 static std::shared_ptr<T>
parse(CharIterator bytes_begin, CharIterator bytes_end,
80 CharIterator& actual_end,
const std::string&
type =
type_name())
83 bytes_begin, bytes_end, actual_end,
type);
85 return std::make_shared<T>(j->template get<T>());
90 typename std::enable_if<std::is_same<T, nlohmann::json>::value>
::type* =
nullptr>
Enumeration and helper functions for marshalling scheme identification.
static std::string type_name(const T &t=T())
static std::shared_ptr< DataType > parse(CharIterator bytes_begin, CharIterator bytes_end, CharIterator &actual_end, const std::string &type=type_name())
Given a beginning and end iterator to bytes, parse the data and return it.
static std::shared_ptr< T > parse(CharIterator bytes_begin, CharIterator bytes_end, CharIterator &actual_end, const std::string &type=type_name())
The global namespace for the Goby project.
Class for parsing and serializing a given marshalling scheme. Must be specialized for a particular sc...
constexpr const char * json_type_name()
static std::vector< char > serialize(const nlohmann::json &msg)
static std::string type_name(const nlohmann::json &d=nlohmann::json())
static std::vector< char > serialize(const DataType &)
Given data, produce a vector of bytes.
namespace for Niels Lohmann
static std::string type_name()
The marshalling scheme specific string name for this type.
type
Generic JSON types used in JWTs.
extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, ::google::protobuf::internal::MessageTypeTraits< ::goby::GobyMessageOptions >, 11, false > msg
static std::vector< char > serialize(const T &msg)
basic_json<> json
default specialization
constexpr int scheme()
Placeholder to provide an interface for the scheme() function family.
static std::shared_ptr< nlohmann::json > parse(CharIterator bytes_begin, CharIterator bytes_end, CharIterator &actual_end, const std::string &type=type_name())