lokinet/llarp/util/json.hpp

46 lines
882 B
C++
Raw Normal View History

2019-02-15 23:04:04 +00:00
#ifndef LLARP_UTIL_JSON_HPP
#define LLARP_UTIL_JSON_HPP
#include <nlohmann/json.hpp>
2019-02-15 23:04:04 +00:00
#include <memory>
2019-02-08 22:44:21 +00:00
#include <iostream>
2019-02-15 23:04:04 +00:00
namespace llarp
2018-10-25 17:03:25 +00:00
{
namespace json
{
2019-06-13 13:26:34 +00:00
using Object = nlohmann::json;
2018-10-25 17:03:25 +00:00
struct IParser
{
2019-07-30 23:42:13 +00:00
virtual ~IParser() = default;
2018-10-25 17:03:25 +00:00
/// result from feeding data to parser
enum Result
{
/// we need more data to finish parsing
eNeedData,
/// we have parsed the object fully
eDone,
/// we have a parsing syntax error
eParseError
};
/// feed data to parser return true if successful
virtual bool
FeedData(const char* buf, size_t sz) = 0;
2018-10-25 17:03:25 +00:00
/// parse internal buffer
virtual Result
2019-06-13 13:26:34 +00:00
Parse(Object& obj) const = 0;
2018-10-25 17:03:25 +00:00
};
/// create new parser
IParser*
2018-10-25 17:03:25 +00:00
MakeParser(size_t contentSize);
} // namespace json
2019-02-15 23:04:04 +00:00
} // namespace llarp
#endif