• 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_PARSER_HANDLER_H_
6 #define V8_CRDTP_PARSER_HANDLER_H_
7 
8 #include <cstdint>
9 #include "span.h"
10 #include "status.h"
11 
12 namespace v8_crdtp {
13 // Handler interface for parser events emitted by a streaming parser.
14 // See cbor::NewCBOREncoder, cbor::ParseCBOR, json::NewJSONEncoder,
15 // json::ParseJSON.
16 class ParserHandler {
17  public:
18   virtual ~ParserHandler() = default;
19   virtual void HandleMapBegin() = 0;
20   virtual void HandleMapEnd() = 0;
21   virtual void HandleArrayBegin() = 0;
22   virtual void HandleArrayEnd() = 0;
23   virtual void HandleString8(span<uint8_t> chars) = 0;
24   virtual void HandleString16(span<uint16_t> chars) = 0;
25   virtual void HandleBinary(span<uint8_t> bytes) = 0;
26   virtual void HandleDouble(double value) = 0;
27   virtual void HandleInt32(int32_t value) = 0;
28   virtual void HandleBool(bool value) = 0;
29   virtual void HandleNull() = 0;
30 
31   // The parser may send one error even after other events have already
32   // been received. Client code is reponsible to then discard the
33   // already processed events.
34   // |error| must be an eror, as in, |error.is_ok()| can't be true.
35   virtual void HandleError(Status error) = 0;
36 };
37 }  // namespace v8_crdtp
38 
39 #endif  // V8_CRDTP_PARSER_HANDLER_H_
40