• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_CRDTP_JSON_H_
6 #define V8_CRDTP_JSON_H_
7 
8 #include <memory>
9 #include <vector>
10 #include "export.h"
11 #include "parser_handler.h"
12 
13 namespace v8_crdtp {
14 namespace json {
15 // =============================================================================
16 // json::NewJSONEncoder - for encoding streaming parser events as JSON
17 // =============================================================================
18 
19 // Returns a handler object which will write ascii characters to |out|.
20 // |status->ok()| will be false iff the handler routine HandleError() is called.
21 // In that case, we'll stop emitting output.
22 // Except for calling the HandleError routine at any time, the client
23 // code must call the Handle* methods in an order in which they'd occur
24 // in valid JSON; otherwise we may crash (the code uses assert).
25 std::unique_ptr<ParserHandler> NewJSONEncoder(std::vector<uint8_t>* out,
26                                               Status* status);
27 
28 std::unique_ptr<ParserHandler> NewJSONEncoder(std::string* out, Status* status);
29 
30 // =============================================================================
31 // json::ParseJSON - for receiving streaming parser events for JSON
32 // =============================================================================
33 
34 void ParseJSON(span<uint8_t> chars, ParserHandler* handler);
35 
36 void ParseJSON(span<uint16_t> chars, ParserHandler* handler);
37 
38 // =============================================================================
39 // json::ConvertCBORToJSON, json::ConvertJSONToCBOR - for transcoding
40 // =============================================================================
41 
42 Status ConvertCBORToJSON(span<uint8_t> cbor, std::string* json);
43 
44 Status ConvertCBORToJSON(span<uint8_t> cbor, std::vector<uint8_t>* json);
45 
46 Status ConvertJSONToCBOR(span<uint8_t> json, std::vector<uint8_t>* cbor);
47 
48 Status ConvertJSONToCBOR(span<uint16_t> json, std::vector<uint8_t>* cbor);
49 }  // namespace json
50 }  // namespace v8_crdtp
51 
52 #endif  // V8_CRDTP_JSON_H_
53