/*!\file serialization_json.cpp\brief Fast Binary Encoding JSON serialization example\author Ivan Shynkarenka\date 20.06.2018\copyright MIT License*/#include "../proto/proto_json.h"#include <iostream>int main(int argc, char** argv){// Create a new account with some ordersproto::Account account = { 1, "Test", proto::State::good, { "USD", 1000.0 }, std::make_optional<proto::Balance>({ "EUR", 100.0 }), {} };account.orders.emplace_back(1, "EURUSD", proto::OrderSide::buy, proto::OrderType::market, 1.23456, 1000.0);account.orders.emplace_back(2, "EURUSD", proto::OrderSide::sell, proto::OrderType::limit, 1.0, 100.0);account.orders.emplace_back(3, "EURUSD", proto::OrderSide::buy, proto::OrderType::stop, 1.5, 10.0);// Serialize the account to the JSON streamrapidjson::StringBuffer buffer;rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);FBE::JSON::to_json(writer, account);// Show the serialized JSON and its sizestd::cout << "JSON: " << buffer.GetString() << std::endl;std::cout << "JSON size: " << buffer.GetSize() << std::endl;// Parse the JSON documentrapidjson::Document json;json.Parse(buffer.GetString());// Deserialize the account from the JSON streamFBE::JSON::from_json(json, account);// Show account contentstd::cout << std::endl;std::cout << account;return 0;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。