json-related refactor
This commit is contained in:
+14
-14
@@ -11,20 +11,20 @@ namespace dynamic {
|
||||
}
|
||||
|
||||
namespace json {
|
||||
const int BJSON_END = 0x0;
|
||||
const int BJSON_TYPE_DOCUMENT = 0x1;
|
||||
const int BJSON_TYPE_LIST = 0x2;
|
||||
const int BJSON_TYPE_BYTE = 0x3;
|
||||
const int BJSON_TYPE_INT16 = 0x4;
|
||||
const int BJSON_TYPE_INT32 = 0x5;
|
||||
const int BJSON_TYPE_INT64 = 0x6;
|
||||
const int BJSON_TYPE_NUMBER = 0x7;
|
||||
const int BJSON_TYPE_STRING = 0x8;
|
||||
const int BJSON_TYPE_BYTES = 0x9;
|
||||
const int BJSON_TYPE_FALSE = 0xA;
|
||||
const int BJSON_TYPE_TRUE = 0xB;
|
||||
const int BJSON_TYPE_NULL = 0xC;
|
||||
const int BJSON_TYPE_CDOCUMENT = 0x1F;
|
||||
inline constexpr int BJSON_END = 0x0;
|
||||
inline constexpr int BJSON_TYPE_DOCUMENT = 0x1;
|
||||
inline constexpr int BJSON_TYPE_LIST = 0x2;
|
||||
inline constexpr int BJSON_TYPE_BYTE = 0x3;
|
||||
inline constexpr int BJSON_TYPE_INT16 = 0x4;
|
||||
inline constexpr int BJSON_TYPE_INT32 = 0x5;
|
||||
inline constexpr int BJSON_TYPE_INT64 = 0x6;
|
||||
inline constexpr int BJSON_TYPE_NUMBER = 0x7;
|
||||
inline constexpr int BJSON_TYPE_STRING = 0x8;
|
||||
inline constexpr int BJSON_TYPE_BYTES = 0x9;
|
||||
inline constexpr int BJSON_TYPE_FALSE = 0xA;
|
||||
inline constexpr int BJSON_TYPE_TRUE = 0xB;
|
||||
inline constexpr int BJSON_TYPE_NULL = 0xC;
|
||||
inline constexpr int BJSON_TYPE_CDOCUMENT = 0x1F;
|
||||
|
||||
extern std::vector<ubyte> to_binary(const dynamic::Map* obj, bool compress=false);
|
||||
extern std::shared_ptr<dynamic::Map> from_binary(const ubyte* src, size_t size);
|
||||
|
||||
+4
-2
@@ -1,5 +1,7 @@
|
||||
#include "json.hpp"
|
||||
|
||||
#include "commons.hpp"
|
||||
|
||||
#include "../data/dynamic.hpp"
|
||||
#include "../util/stringutil.hpp"
|
||||
|
||||
@@ -240,11 +242,11 @@ Value Parser::parseValue() {
|
||||
throw error("unexpected character '"+std::string({next})+"'");
|
||||
}
|
||||
|
||||
std::unique_ptr<Map> json::parse(const std::string& filename, const std::string& source) {
|
||||
dynamic::Map_sptr json::parse(const std::string& filename, const std::string& source) {
|
||||
Parser parser(filename, source);
|
||||
return parser.parse();
|
||||
}
|
||||
|
||||
std::unique_ptr<Map> json::parse(const std::string& source) {
|
||||
dynamic::Map_sptr json::parse(const std::string& source) {
|
||||
return parse("<string>", source);
|
||||
}
|
||||
|
||||
+4
-9
@@ -1,25 +1,20 @@
|
||||
#ifndef CODERS_JSON_HPP_
|
||||
#define CODERS_JSON_HPP_
|
||||
|
||||
#include "commons.hpp"
|
||||
#include "binary_json.hpp"
|
||||
|
||||
#include "../data/dynamic.hpp"
|
||||
#include "../typedefs.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include <stdexcept>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace json {
|
||||
std::unique_ptr<dynamic::Map> parse(const std::string& filename, const std::string& source);
|
||||
std::unique_ptr<dynamic::Map> parse(const std::string& source);
|
||||
dynamic::Map_sptr parse(const std::string& filename, const std::string& source);
|
||||
dynamic::Map_sptr parse(const std::string& source);
|
||||
|
||||
std::string stringify(
|
||||
const dynamic::Map* obj,
|
||||
bool nice,
|
||||
const dynamic::Map* obj,
|
||||
bool nice,
|
||||
const std::string& indent
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user