Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
simplepullreader.cpp
Go to the documentation of this file.
1
#include "
rapidjson/reader.h
"
2
#include <iostream>
3
#include <sstream>
4
5
using namespace
rapidjson
;
6
using namespace
std
;
7
8
// If you can require C++11, you could use std::to_string here
9
template
<
typename
T> std::string
stringify
(
T
x) {
10
std::stringstream ss;
11
ss << x;
12
return
ss.str();
13
}
14
15
struct
MyHandler
{
16
const
char
*
type
;
17
std::string
data
;
18
19
MyHandler
() :
type
(),
data
() {}
20
21
bool
Null
() {
type
=
"Null"
;
data
.clear();
return
true
; }
22
bool
Bool
(
bool
b) {
type
=
"Bool:"
;
data
= b?
"true"
:
"false"
;
return
true
; }
23
bool
Int
(
int
i) {
type
=
"Int:"
;
data
=
stringify
(i);
return
true
; }
24
bool
Uint
(
unsigned
u) {
type
=
"Uint:"
;
data
=
stringify
(u);
return
true
; }
25
bool
Int64
(
int64_t
i) {
type
=
"Int64:"
;
data
=
stringify
(i);
return
true
; }
26
bool
Uint64
(
uint64_t
u) {
type
=
"Uint64:"
;
data
=
stringify
(u);
return
true
; }
27
bool
Double
(
double
d) {
type
=
"Double:"
;
data
=
stringify
(d);
return
true
; }
28
bool
RawNumber
(
const
char
* str,
SizeType
length,
bool
) {
type
=
"Number:"
;
data
= std::string(str, length);
return
true
; }
29
bool
String
(
const
char
* str,
SizeType
length,
bool
) {
type
=
"String:"
;
data
= std::string(str, length);
return
true
; }
30
bool
StartObject
() {
type
=
"StartObject"
;
data
.clear();
return
true
; }
31
bool
Key
(
const
char
* str,
SizeType
length,
bool
) {
type
=
"Key:"
;
data
= std::string(str, length);
return
true
; }
32
bool
EndObject
(
SizeType
memberCount) {
type
=
"EndObject:"
;
data
=
stringify
(memberCount);
return
true
; }
33
bool
StartArray
() {
type
=
"StartArray"
;
data
.clear();
return
true
; }
34
bool
EndArray
(
SizeType
elementCount) {
type
=
"EndArray:"
;
data
=
stringify
(elementCount);
return
true
; }
35
private
:
36
MyHandler
(
const
MyHandler
& noCopyConstruction);
37
MyHandler
&
operator=
(
const
MyHandler
& noAssignment);
38
};
39
40
int
main
() {
41
const
char
json
[] =
" { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } "
;
42
43
MyHandler
handler;
44
Reader
reader;
45
StringStream
ss(
json
);
46
reader.
IterativeParseInit
();
47
while
(!reader.
IterativeParseComplete
()) {
48
reader.
IterativeParseNext
<
kParseDefaultFlags
>(ss, handler);
49
cout << handler.
type
<< handler.
data
<< endl;
50
}
51
52
return
0;
53
}
operator=
connection< TProtocol > & operator=(const connection< TProtocol > &obj)
Definition
abstract_tcp_server_cp.h:196
GenericReader::IterativeParseNext
bool IterativeParseNext(InputStream &is, Handler &handler)
Parse one token from JSON text.
Definition
reader.h:618
GenericReader::IterativeParseInit
void IterativeParseInit()
Initialize JSON text token-by-token parsing.
Definition
reader.h:605
GenericReader::IterativeParseComplete
RAPIDJSON_FORCEINLINE bool IterativeParseComplete() const
Check if token-by-token parsing JSON text is complete.
Definition
reader.h:675
StringStream
GenericStringStream< UTF8< char > > StringStream
Definition
fwd.h:49
Reader
GenericReader< UTF8< char >, UTF8< char >, CrtAllocator > Reader
Definition
fwd.h:90
rapidjson
main RapidJSON namespace
std
STL namespace.
SizeType
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.).
Definition
rapidjson.h:389
reader.h
kParseDefaultFlags
@ kParseDefaultFlags
Default parse flags. Can be customized by defining RAPIDJSON_PARSE_DEFAULT_FLAGS.
Definition
reader.h:156
stringify
std::string stringify(T x)
Definition
simplepullreader.cpp:9
main
int main()
Definition
simplepullreader.cpp:40
int64_t
signed __int64 int64_t
Definition
stdint.h:135
uint64_t
unsigned __int64 uint64_t
Definition
stdint.h:136
MyHandler
Definition
simplepullreader.cpp:15
MyHandler::StartArray
bool StartArray()
Definition
simplepullreader.cpp:33
MyHandler::Bool
bool Bool(bool b)
Definition
simplepullreader.cpp:22
MyHandler::EndObject
bool EndObject(SizeType memberCount)
Definition
simplepullreader.cpp:32
MyHandler::data
std::string data
Definition
simplepullreader.cpp:17
MyHandler::Uint
bool Uint(unsigned u)
Definition
simplepullreader.cpp:24
MyHandler::RawNumber
bool RawNumber(const char *str, SizeType length, bool)
Definition
simplepullreader.cpp:28
MyHandler::Int64
bool Int64(int64_t i)
Definition
simplepullreader.cpp:25
MyHandler::type
const char * type
Definition
simplepullreader.cpp:16
MyHandler::String
bool String(const char *str, SizeType length, bool)
Definition
simplepullreader.cpp:29
MyHandler::Double
bool Double(double d)
Definition
simplepullreader.cpp:27
MyHandler::Null
bool Null()
Definition
simplepullreader.cpp:21
MyHandler::EndArray
bool EndArray(SizeType elementCount)
Definition
simplepullreader.cpp:34
MyHandler::Uint64
bool Uint64(uint64_t u)
Definition
simplepullreader.cpp:26
MyHandler::Int
bool Int(int i)
Definition
simplepullreader.cpp:23
MyHandler::MyHandler
MyHandler()
Definition
simplepullreader.cpp:19
MyHandler::StartObject
bool StartObject()
Definition
simplepullreader.cpp:30
MyHandler::Key
bool Key(const char *str, SizeType length, bool)
Definition
simplepullreader.cpp:31
json
rapidjson::Document json
Definition
transport.cpp:49
T
#define T(x)
external
rapidjson
example
simplepullreader
simplepullreader.cpp
Generated on
for Electroneum by
1.17.0