Electroneum
filterkey.cpp File Reference
#include "rapidjson/reader.h"
#include "rapidjson/writer.h"
#include "rapidjson/filereadstream.h"
#include "rapidjson/filewritestream.h"
#include "rapidjson/error/en.h"
#include <stack>
Include dependency graph for filterkey.cpp:

Go to the source code of this file.

Classes

class  FilterKeyHandler< OutputHandler >
 

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 108 of file filterkey.cpp.

108  {
109  if (argc != 2) {
110  fprintf(stderr, "filterkey key < input.json > output.json\n");
111  return 1;
112  }
113 
114  // Prepare JSON reader and input stream.
115  Reader reader;
116  char readBuffer[65536];
117  FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
118 
119  // Prepare JSON writer and output stream.
120  char writeBuffer[65536];
121  FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
122  Writer<FileWriteStream> writer(os);
123 
124  // Prepare Filter
125  FilterKeyHandler<Writer<FileWriteStream> > filter(writer, argv[1], static_cast<SizeType>(strlen(argv[1])));
126 
127  // JSON reader parse from the input stream, filter handler filters the events, and forward to writer.
128  // i.e. the events flow is: reader -> filter -> writer
129  if (!reader.Parse(is, filter)) {
130  fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode()));
131  return 1;
132  }
133 
134  return 0;
135 }
JSON writer.
Definition: fwd.h:95
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:557
File byte stream for input using fread().
RAPIDJSON_NAMESPACE_BEGIN const RAPIDJSON_ERROR_CHARTYPE * GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
Definition: en.h:36
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
Definition: reader.h:683
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition: reader.h:686
Wrapper of C file stream for output using fwrite().
Here is the call graph for this function: