parser_handler.h 1.3 KB

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