#pragma once
#ifndef ROCKSDB_LITE
#include <deque>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "rocksdb/slice.h"
namespace
fbson {
class
FbsonValue;
class
ObjectVal;
template
<
typename
T>
class
FbsonWriterT;
class
FbsonOutStream;
typedef
FbsonWriterT<FbsonOutStream> FbsonWriter;
}
namespace
rocksdb {
class
JSONDocument {
public
:
static
JSONDocument* ParseJSON(
const
char
* json);
enum
Type {
kNull,
kArray,
kBool,
kDouble,
kInt64,
kObject,
kString,
};
JSONDocument();
JSONDocument(
bool
b);
JSONDocument(
double
d);
JSONDocument(int8_t i);
JSONDocument(int16_t i);
JSONDocument(int32_t i);
JSONDocument(int64_t i);
JSONDocument(
const
std::string& s);
JSONDocument(
const
char
* s);
explicit
JSONDocument(Type _type);
JSONDocument(
const
JSONDocument& json_document);
JSONDocument(JSONDocument&& json_document);
Type type()
const
;
bool
Contains(
const
std::string& key)
const
;
JSONDocument operator[](
const
std::string& key)
const
;
size_t
Count()
const
;
JSONDocument operator[](
size_t
i)
const
;
JSONDocument& operator=(JSONDocument jsonDocument);
bool
IsNull()
const
;
bool
IsArray()
const
;
bool
IsBool()
const
;
bool
IsDouble()
const
;
bool
IsInt64()
const
;
bool
IsObject()
const
;
bool
IsString()
const
;
bool
GetBool()
const
;
double
GetDouble()
const
;
int64_t GetInt64()
const
;
std::string GetString()
const
;
bool
operator==(
const
JSONDocument& rhs)
const
;
bool
operator!=(
const
JSONDocument& rhs)
const
;
JSONDocument Copy()
const
;
bool
IsOwner()
const
;
std::string DebugString()
const
;
private
:
class
ItemsIteratorGenerator;
public
:
ItemsIteratorGenerator Items()
const
;
void
Serialize(std::string* dst)
const
;
static
JSONDocument* Deserialize(
const
Slice& src);
private
:
friend
class
JSONDocumentBuilder;
JSONDocument(fbson::FbsonValue* val,
bool
makeCopy);
void
InitFromValue(
const
fbson::FbsonValue* val);
class
const_item_iterator {
private
:
class
Impl;
public
:
typedef
std::pair<std::string, JSONDocument> value_type;
explicit
const_item_iterator(Impl* impl);
const_item_iterator(const_item_iterator&&);
const_item_iterator& operator++();
bool
operator!=(
const
const_item_iterator& other);
value_type operator*();
~const_item_iterator();
private
:
friend
class
ItemsIteratorGenerator;
std::unique_ptr<Impl> it_;
};
class
ItemsIteratorGenerator {
public
:
explicit
ItemsIteratorGenerator(
const
fbson::ObjectVal& object);
const_item_iterator begin()
const
;
const_item_iterator end()
const
;
private
:
const
fbson::ObjectVal& object_;
};
std::unique_ptr<
char
[]> data_;
mutable
fbson::FbsonValue* value_;
static
const
char
kSerializationFormatVersion;
};
class
JSONDocumentBuilder {
public
:
JSONDocumentBuilder();
explicit
JSONDocumentBuilder(fbson::FbsonOutStream* out);
void
Reset();
bool
WriteStartArray();
bool
WriteEndArray();
bool
WriteStartObject();
bool
WriteEndObject();
bool
WriteKeyValue(
const
std::string& key,
const
JSONDocument& value);
bool
WriteJSONDocument(
const
JSONDocument& value);
JSONDocument GetJSONDocument();
~JSONDocumentBuilder();
private
:
std::unique_ptr<fbson::FbsonWriter> writer_;
};
}
#endif // ROCKSDB_LITE