Commit f6a76fad authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Roll inspector protocol (Cleanup) (V8)

New revision: 4c2a3acaea9f2e7958081dd361f81e20e9eff5e7

This cleanup cl does not change any behavior, it just
cleans up some headers and does a class rename
(StreamingParserHandler->ParserHandler). It was reviewed
upstream
https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/1924792
https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/1925679
and does not touch V8 code. Would like to get
this in to make it easier to review subsequent changes.

Thanks!

Change-Id: Ie9fe1434bafeb4f5090244f823d1e482ff805dd0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1925721
Auto-Submit: Johannes Henkel <johannes@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65106}
parent 316036bc
...@@ -2,7 +2,7 @@ Name: inspector protocol ...@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/ URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0 Version: 0
Revision: d020a9e614d4a5116a7c71f288c0340e282e1a6e Revision: 4c2a3acaea9f2e7958081dd361f81e20e9eff5e7
License: BSD License: BSD
License File: LICENSE License File: LICENSE
Security Critical: no Security Critical: no
......
...@@ -114,7 +114,7 @@ def read_config(): ...@@ -114,7 +114,7 @@ def read_config():
".lib.export_header": False, ".lib.export_header": False,
".crdtp": False, ".crdtp": False,
".crdtp.dir": os.path.join(inspector_protocol_dir, "crdtp"), ".crdtp.dir": os.path.join(inspector_protocol_dir, "crdtp"),
".crdtp.namespace": "inspector_protocol", ".crdtp.namespace": "crdtp",
} }
for key_value in config_values: for key_value in config_values:
parts = key_value.split("=") parts = key_value.split("=")
......
...@@ -451,7 +451,7 @@ bool EnvelopeEncoder::EncodeStop(std::string* out) { ...@@ -451,7 +451,7 @@ bool EnvelopeEncoder::EncodeStop(std::string* out) {
namespace { namespace {
template <typename C> template <typename C>
class CBOREncoder : public StreamingParserHandler { class CBOREncoder : public ParserHandler {
public: public:
CBOREncoder(C* out, Status* status) : out_(out), status_(status) { CBOREncoder(C* out, Status* status) : out_(out), status_(status) {
*status_ = Status(); *status_ = Status();
...@@ -557,16 +557,14 @@ class CBOREncoder : public StreamingParserHandler { ...@@ -557,16 +557,14 @@ class CBOREncoder : public StreamingParserHandler {
}; };
} // namespace } // namespace
std::unique_ptr<StreamingParserHandler> NewCBOREncoder( std::unique_ptr<ParserHandler> NewCBOREncoder(std::vector<uint8_t>* out,
std::vector<uint8_t>* out,
Status* status) { Status* status) {
return std::unique_ptr<StreamingParserHandler>( return std::unique_ptr<ParserHandler>(
new CBOREncoder<std::vector<uint8_t>>(out, status)); new CBOREncoder<std::vector<uint8_t>>(out, status));
} }
std::unique_ptr<ParserHandler> NewCBOREncoder(std::string* out,
std::unique_ptr<StreamingParserHandler> NewCBOREncoder(std::string* out,
Status* status) { Status* status) {
return std::unique_ptr<StreamingParserHandler>( return std::unique_ptr<ParserHandler>(
new CBOREncoder<std::string>(out, status)); new CBOREncoder<std::string>(out, status));
} }
...@@ -870,21 +868,18 @@ static constexpr int kStackLimit = 300; ...@@ -870,21 +868,18 @@ static constexpr int kStackLimit = 300;
// to roundtrip JSON messages. // to roundtrip JSON messages.
bool ParseMap(int32_t stack_depth, bool ParseMap(int32_t stack_depth,
CBORTokenizer* tokenizer, CBORTokenizer* tokenizer,
StreamingParserHandler* out); ParserHandler* out);
bool ParseArray(int32_t stack_depth, bool ParseArray(int32_t stack_depth,
CBORTokenizer* tokenizer, CBORTokenizer* tokenizer,
StreamingParserHandler* out); ParserHandler* out);
bool ParseValue(int32_t stack_depth, bool ParseValue(int32_t stack_depth,
CBORTokenizer* tokenizer, CBORTokenizer* tokenizer,
StreamingParserHandler* out); ParserHandler* out);
bool ParseEnvelope(int32_t stack_depth, bool ParseEnvelope(int32_t stack_depth,
CBORTokenizer* tokenizer, CBORTokenizer* tokenizer,
StreamingParserHandler* out); ParserHandler* out);
void ParseUTF16String(CBORTokenizer* tokenizer, StreamingParserHandler* out) { void ParseUTF16String(CBORTokenizer* tokenizer, ParserHandler* out) {
std::vector<uint16_t> value; std::vector<uint16_t> value;
span<uint8_t> rep = tokenizer->GetString16WireRep(); span<uint8_t> rep = tokenizer->GetString16WireRep();
for (size_t ii = 0; ii < rep.size(); ii += 2) for (size_t ii = 0; ii < rep.size(); ii += 2)
...@@ -893,7 +888,7 @@ void ParseUTF16String(CBORTokenizer* tokenizer, StreamingParserHandler* out) { ...@@ -893,7 +888,7 @@ void ParseUTF16String(CBORTokenizer* tokenizer, StreamingParserHandler* out) {
tokenizer->Next(); tokenizer->Next();
} }
bool ParseUTF8String(CBORTokenizer* tokenizer, StreamingParserHandler* out) { bool ParseUTF8String(CBORTokenizer* tokenizer, ParserHandler* out) {
assert(tokenizer->TokenTag() == CBORTokenTag::STRING8); assert(tokenizer->TokenTag() == CBORTokenTag::STRING8);
out->HandleString8(tokenizer->GetString8()); out->HandleString8(tokenizer->GetString8());
tokenizer->Next(); tokenizer->Next();
...@@ -902,7 +897,7 @@ bool ParseUTF8String(CBORTokenizer* tokenizer, StreamingParserHandler* out) { ...@@ -902,7 +897,7 @@ bool ParseUTF8String(CBORTokenizer* tokenizer, StreamingParserHandler* out) {
bool ParseEnvelope(int32_t stack_depth, bool ParseEnvelope(int32_t stack_depth,
CBORTokenizer* tokenizer, CBORTokenizer* tokenizer,
StreamingParserHandler* out) { ParserHandler* out) {
assert(tokenizer->TokenTag() == CBORTokenTag::ENVELOPE); assert(tokenizer->TokenTag() == CBORTokenTag::ENVELOPE);
// Before we enter the envelope, we save the position that we // Before we enter the envelope, we save the position that we
// expect to see after we're done parsing the envelope contents. // expect to see after we're done parsing the envelope contents.
...@@ -948,7 +943,7 @@ bool ParseEnvelope(int32_t stack_depth, ...@@ -948,7 +943,7 @@ bool ParseEnvelope(int32_t stack_depth,
bool ParseValue(int32_t stack_depth, bool ParseValue(int32_t stack_depth,
CBORTokenizer* tokenizer, CBORTokenizer* tokenizer,
StreamingParserHandler* out) { ParserHandler* out) {
if (stack_depth > kStackLimit) { if (stack_depth > kStackLimit) {
out->HandleError( out->HandleError(
Status{Error::CBOR_STACK_LIMIT_EXCEEDED, tokenizer->Status().pos}); Status{Error::CBOR_STACK_LIMIT_EXCEEDED, tokenizer->Status().pos});
...@@ -1010,7 +1005,7 @@ bool ParseValue(int32_t stack_depth, ...@@ -1010,7 +1005,7 @@ bool ParseValue(int32_t stack_depth,
// detected. // detected.
bool ParseArray(int32_t stack_depth, bool ParseArray(int32_t stack_depth,
CBORTokenizer* tokenizer, CBORTokenizer* tokenizer,
StreamingParserHandler* out) { ParserHandler* out) {
assert(tokenizer->TokenTag() == CBORTokenTag::ARRAY_START); assert(tokenizer->TokenTag() == CBORTokenTag::ARRAY_START);
tokenizer->Next(); tokenizer->Next();
out->HandleArrayBegin(); out->HandleArrayBegin();
...@@ -1038,7 +1033,7 @@ bool ParseArray(int32_t stack_depth, ...@@ -1038,7 +1033,7 @@ bool ParseArray(int32_t stack_depth,
// detected. // detected.
bool ParseMap(int32_t stack_depth, bool ParseMap(int32_t stack_depth,
CBORTokenizer* tokenizer, CBORTokenizer* tokenizer,
StreamingParserHandler* out) { ParserHandler* out) {
assert(tokenizer->TokenTag() == CBORTokenTag::MAP_START); assert(tokenizer->TokenTag() == CBORTokenTag::MAP_START);
out->HandleMapBegin(); out->HandleMapBegin();
tokenizer->Next(); tokenizer->Next();
...@@ -1073,7 +1068,7 @@ bool ParseMap(int32_t stack_depth, ...@@ -1073,7 +1068,7 @@ bool ParseMap(int32_t stack_depth,
} }
} // namespace } // namespace
void ParseCBOR(span<uint8_t> bytes, StreamingParserHandler* out) { void ParseCBOR(span<uint8_t> bytes, ParserHandler* out) {
if (bytes.empty()) { if (bytes.empty()) {
out->HandleError(Status{Error::CBOR_NO_INPUT, 0}); out->HandleError(Status{Error::CBOR_NO_INPUT, 0});
return; return;
......
...@@ -5,11 +5,8 @@ ...@@ -5,11 +5,8 @@
#ifndef V8_CRDTP_CBOR_H_ #ifndef V8_CRDTP_CBOR_H_
#define V8_CRDTP_CBOR_H_ #define V8_CRDTP_CBOR_H_
#include <algorithm>
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <cstring>
#include <limits>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -140,11 +137,9 @@ class EnvelopeEncoder { ...@@ -140,11 +137,9 @@ class EnvelopeEncoder {
// that drives it. The handler will encode into |out|, and iff an error occurs // that drives it. The handler will encode into |out|, and iff an error occurs
// it will set |status| to an error and clear |out|. Otherwise, |status.ok()| // it will set |status| to an error and clear |out|. Otherwise, |status.ok()|
// will be |true|. // will be |true|.
std::unique_ptr<StreamingParserHandler> NewCBOREncoder( std::unique_ptr<ParserHandler> NewCBOREncoder(std::vector<uint8_t>* out,
std::vector<uint8_t>* out,
Status* status);
std::unique_ptr<StreamingParserHandler> NewCBOREncoder(std::string* out,
Status* status); Status* status);
std::unique_ptr<ParserHandler> NewCBOREncoder(std::string* out, Status* status);
// ============================================================================= // =============================================================================
// cbor::CBORTokenizer - for parsing individual CBOR items // cbor::CBORTokenizer - for parsing individual CBOR items
...@@ -283,7 +278,7 @@ class CBORTokenizer { ...@@ -283,7 +278,7 @@ class CBORTokenizer {
// |out|. If an error occurs, sends |out->HandleError|, and parsing stops. // |out|. If an error occurs, sends |out->HandleError|, and parsing stops.
// The client is responsible for discarding the already received information in // The client is responsible for discarding the already received information in
// that case. // that case.
void ParseCBOR(span<uint8_t> bytes, StreamingParserHandler* out); void ParseCBOR(span<uint8_t> bytes, ParserHandler* out);
// ============================================================================= // =============================================================================
// cbor::AppendString8EntryToMap - for limited in-place editing of messages // cbor::AppendString8EntryToMap - for limited in-place editing of messages
......
...@@ -102,7 +102,7 @@ void Base64Encode(const span<uint8_t>& in, C* out) { ...@@ -102,7 +102,7 @@ void Base64Encode(const span<uint8_t>& in, C* out) {
// Implements a handler for JSON parser events to emit a JSON string. // Implements a handler for JSON parser events to emit a JSON string.
template <typename C> template <typename C>
class JSONEncoder : public StreamingParserHandler { class JSONEncoder : public ParserHandler {
public: public:
JSONEncoder(const Platform* platform, C* out, Status* status) JSONEncoder(const Platform* platform, C* out, Status* status)
: platform_(platform), out_(out), status_(status) { : platform_(platform), out_(out), status_(status) {
...@@ -343,18 +343,17 @@ class JSONEncoder : public StreamingParserHandler { ...@@ -343,18 +343,17 @@ class JSONEncoder : public StreamingParserHandler {
}; };
} // namespace } // namespace
std::unique_ptr<StreamingParserHandler> NewJSONEncoder( std::unique_ptr<ParserHandler> NewJSONEncoder(const Platform* platform,
const Platform* platform,
std::vector<uint8_t>* out, std::vector<uint8_t>* out,
Status* status) { Status* status) {
return std::unique_ptr<StreamingParserHandler>( return std::unique_ptr<ParserHandler>(
new JSONEncoder<std::vector<uint8_t>>(platform, out, status)); new JSONEncoder<std::vector<uint8_t>>(platform, out, status));
} }
std::unique_ptr<StreamingParserHandler> NewJSONEncoder(const Platform* platform, std::unique_ptr<ParserHandler> NewJSONEncoder(const Platform* platform,
std::string* out, std::string* out,
Status* status) { Status* status) {
return std::unique_ptr<StreamingParserHandler>( return std::unique_ptr<ParserHandler>(
new JSONEncoder<std::string>(platform, out, status)); new JSONEncoder<std::string>(platform, out, status));
} }
...@@ -388,7 +387,7 @@ const char* const kFalseString = "false"; ...@@ -388,7 +387,7 @@ const char* const kFalseString = "false";
template <typename Char> template <typename Char>
class JsonParser { class JsonParser {
public: public:
JsonParser(const Platform* platform, StreamingParserHandler* handler) JsonParser(const Platform* platform, ParserHandler* handler)
: platform_(platform), handler_(handler) {} : platform_(platform), handler_(handler) {}
void Parse(const Char* start, size_t length) { void Parse(const Char* start, size_t length) {
...@@ -968,20 +967,20 @@ class JsonParser { ...@@ -968,20 +967,20 @@ class JsonParser {
const Char* start_pos_ = nullptr; const Char* start_pos_ = nullptr;
bool error_ = false; bool error_ = false;
const Platform* platform_; const Platform* platform_;
StreamingParserHandler* handler_; ParserHandler* handler_;
}; };
} // namespace } // namespace
void ParseJSON(const Platform& platform, void ParseJSON(const Platform& platform,
span<uint8_t> chars, span<uint8_t> chars,
StreamingParserHandler* handler) { ParserHandler* handler) {
JsonParser<uint8_t> parser(&platform, handler); JsonParser<uint8_t> parser(&platform, handler);
parser.Parse(chars.data(), chars.size()); parser.Parse(chars.data(), chars.size());
} }
void ParseJSON(const Platform& platform, void ParseJSON(const Platform& platform,
span<uint16_t> chars, span<uint16_t> chars,
StreamingParserHandler* handler) { ParserHandler* handler) {
JsonParser<uint16_t> parser(&platform, handler); JsonParser<uint16_t> parser(&platform, handler);
parser.Parse(chars.data(), chars.size()); parser.Parse(chars.data(), chars.size());
} }
...@@ -994,7 +993,7 @@ Status ConvertCBORToJSONTmpl(const Platform& platform, ...@@ -994,7 +993,7 @@ Status ConvertCBORToJSONTmpl(const Platform& platform,
span<uint8_t> cbor, span<uint8_t> cbor,
C* json) { C* json) {
Status status; Status status;
std::unique_ptr<StreamingParserHandler> json_writer = std::unique_ptr<ParserHandler> json_writer =
NewJSONEncoder(&platform, json, &status); NewJSONEncoder(&platform, json, &status);
cbor::ParseCBOR(cbor, json_writer.get()); cbor::ParseCBOR(cbor, json_writer.get());
return status; return status;
...@@ -1015,8 +1014,7 @@ Status ConvertCBORToJSON(const Platform& platform, ...@@ -1015,8 +1014,7 @@ Status ConvertCBORToJSON(const Platform& platform,
template <typename T, typename C> template <typename T, typename C>
Status ConvertJSONToCBORTmpl(const Platform& platform, span<T> json, C* cbor) { Status ConvertJSONToCBORTmpl(const Platform& platform, span<T> json, C* cbor) {
Status status; Status status;
std::unique_ptr<StreamingParserHandler> encoder = std::unique_ptr<ParserHandler> encoder = cbor::NewCBOREncoder(cbor, &status);
cbor::NewCBOREncoder(cbor, &status);
ParseJSON(platform, json, encoder.get()); ParseJSON(platform, json, encoder.get());
return status; return status;
} }
......
...@@ -5,14 +5,7 @@ ...@@ -5,14 +5,7 @@
#ifndef V8_CRDTP_JSON_H_ #ifndef V8_CRDTP_JSON_H_
#define V8_CRDTP_JSON_H_ #define V8_CRDTP_JSON_H_
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <memory> #include <memory>
#include <string>
#include <vector>
#include "export.h" #include "export.h"
#include "json_platform.h" #include "json_platform.h"
...@@ -30,11 +23,10 @@ namespace json { ...@@ -30,11 +23,10 @@ namespace json {
// Except for calling the HandleError routine at any time, the client // Except for calling the HandleError routine at any time, the client
// code must call the Handle* methods in an order in which they'd occur // code must call the Handle* methods in an order in which they'd occur
// in valid JSON; otherwise we may crash (the code uses assert). // in valid JSON; otherwise we may crash (the code uses assert).
std::unique_ptr<StreamingParserHandler> NewJSONEncoder( std::unique_ptr<ParserHandler> NewJSONEncoder(const Platform* platform,
const Platform* platform,
std::vector<uint8_t>* out, std::vector<uint8_t>* out,
Status* status); Status* status);
std::unique_ptr<StreamingParserHandler> NewJSONEncoder(const Platform* platform, std::unique_ptr<ParserHandler> NewJSONEncoder(const Platform* platform,
std::string* out, std::string* out,
Status* status); Status* status);
...@@ -44,10 +36,10 @@ std::unique_ptr<StreamingParserHandler> NewJSONEncoder(const Platform* platform, ...@@ -44,10 +36,10 @@ std::unique_ptr<StreamingParserHandler> NewJSONEncoder(const Platform* platform,
void ParseJSON(const Platform& platform, void ParseJSON(const Platform& platform,
span<uint8_t> chars, span<uint8_t> chars,
StreamingParserHandler* handler); ParserHandler* handler);
void ParseJSON(const Platform& platform, void ParseJSON(const Platform& platform,
span<uint16_t> chars, span<uint16_t> chars,
StreamingParserHandler* handler); ParserHandler* handler);
// ============================================================================= // =============================================================================
// json::ConvertCBORToJSON, json::ConvertJSONToCBOR - for transcoding // json::ConvertCBORToJSON, json::ConvertJSONToCBOR - for transcoding
......
...@@ -5,15 +5,7 @@ ...@@ -5,15 +5,7 @@
#ifndef V8_CRDTP_JSON_PLATFORM_H_ #ifndef V8_CRDTP_JSON_PLATFORM_H_
#define V8_CRDTP_JSON_PLATFORM_H_ #define V8_CRDTP_JSON_PLATFORM_H_
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <memory> #include <memory>
#include <string>
#include <vector>
#include "export.h" #include "export.h"
namespace v8_crdtp { namespace v8_crdtp {
......
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
#include "test_platform.h" #include "test_platform.h"
using testing::ElementsAreArray;
namespace v8_crdtp { namespace v8_crdtp {
namespace { namespace {
class TestPlatform : public json::Platform { class TestPlatform : public json::Platform {
...@@ -61,14 +59,14 @@ namespace json { ...@@ -61,14 +59,14 @@ namespace json {
// json::NewJSONEncoder - for encoding streaming parser events as JSON // json::NewJSONEncoder - for encoding streaming parser events as JSON
// ============================================================================= // =============================================================================
void WriteUTF8AsUTF16(StreamingParserHandler* writer, const std::string& utf8) { void WriteUTF8AsUTF16(ParserHandler* writer, const std::string& utf8) {
writer->HandleString16(SpanFrom(UTF8ToUTF16(SpanFrom(utf8)))); writer->HandleString16(SpanFrom(UTF8ToUTF16(SpanFrom(utf8))));
} }
TEST(JsonEncoder, OverlongEncodings) { TEST(JsonEncoder, OverlongEncodings) {
std::string out; std::string out;
Status status; Status status;
std::unique_ptr<StreamingParserHandler> writer = std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status); NewJSONEncoder(&GetTestPlatform(), &out, &status);
// We encode 0x7f, which is the DEL ascii character, as a 4 byte UTF8 // We encode 0x7f, which is the DEL ascii character, as a 4 byte UTF8
...@@ -87,7 +85,7 @@ TEST(JsonEncoder, OverlongEncodings) { ...@@ -87,7 +85,7 @@ TEST(JsonEncoder, OverlongEncodings) {
TEST(JsonEncoder, IncompleteUtf8Sequence) { TEST(JsonEncoder, IncompleteUtf8Sequence) {
std::string out; std::string out;
Status status; Status status;
std::unique_ptr<StreamingParserHandler> writer = std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status); NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleArrayBegin(); // This emits [, which starts an array. writer->HandleArrayBegin(); // This emits [, which starts an array.
...@@ -113,7 +111,7 @@ TEST(JsonEncoder, IncompleteUtf8Sequence) { ...@@ -113,7 +111,7 @@ TEST(JsonEncoder, IncompleteUtf8Sequence) {
TEST(JsonStdStringWriterTest, HelloWorld) { TEST(JsonStdStringWriterTest, HelloWorld) {
std::string out; std::string out;
Status status; Status status;
std::unique_ptr<StreamingParserHandler> writer = std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status); NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleMapBegin(); writer->HandleMapBegin();
WriteUTF8AsUTF16(writer.get(), "msg1"); WriteUTF8AsUTF16(writer.get(), "msg1");
...@@ -157,7 +155,7 @@ TEST(JsonStdStringWriterTest, RepresentingNonFiniteValuesAsNull) { ...@@ -157,7 +155,7 @@ TEST(JsonStdStringWriterTest, RepresentingNonFiniteValuesAsNull) {
// So in practice it's mapped to null. // So in practice it's mapped to null.
std::string out; std::string out;
Status status; Status status;
std::unique_ptr<StreamingParserHandler> writer = std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status); NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleMapBegin(); writer->HandleMapBegin();
writer->HandleString8(SpanFrom("Infinity")); writer->HandleString8(SpanFrom("Infinity"));
...@@ -172,13 +170,13 @@ TEST(JsonStdStringWriterTest, RepresentingNonFiniteValuesAsNull) { ...@@ -172,13 +170,13 @@ TEST(JsonStdStringWriterTest, RepresentingNonFiniteValuesAsNull) {
} }
TEST(JsonStdStringWriterTest, BinaryEncodedAsJsonString) { TEST(JsonStdStringWriterTest, BinaryEncodedAsJsonString) {
// The encoder emits binary submitted to StreamingParserHandler::HandleBinary // The encoder emits binary submitted to ParserHandler::HandleBinary
// as base64. The following three examples are taken from // as base64. The following three examples are taken from
// https://en.wikipedia.org/wiki/Base64. // https://en.wikipedia.org/wiki/Base64.
{ {
std::string out; std::string out;
Status status; Status status;
std::unique_ptr<StreamingParserHandler> writer = std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status); NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleBinary(SpanFrom(std::vector<uint8_t>({'M', 'a', 'n'}))); writer->HandleBinary(SpanFrom(std::vector<uint8_t>({'M', 'a', 'n'})));
EXPECT_TRUE(status.ok()); EXPECT_TRUE(status.ok());
...@@ -187,7 +185,7 @@ TEST(JsonStdStringWriterTest, BinaryEncodedAsJsonString) { ...@@ -187,7 +185,7 @@ TEST(JsonStdStringWriterTest, BinaryEncodedAsJsonString) {
{ {
std::string out; std::string out;
Status status; Status status;
std::unique_ptr<StreamingParserHandler> writer = std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status); NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleBinary(SpanFrom(std::vector<uint8_t>({'M', 'a'}))); writer->HandleBinary(SpanFrom(std::vector<uint8_t>({'M', 'a'})));
EXPECT_TRUE(status.ok()); EXPECT_TRUE(status.ok());
...@@ -196,7 +194,7 @@ TEST(JsonStdStringWriterTest, BinaryEncodedAsJsonString) { ...@@ -196,7 +194,7 @@ TEST(JsonStdStringWriterTest, BinaryEncodedAsJsonString) {
{ {
std::string out; std::string out;
Status status; Status status;
std::unique_ptr<StreamingParserHandler> writer = std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status); NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleBinary(SpanFrom(std::vector<uint8_t>({'M'}))); writer->HandleBinary(SpanFrom(std::vector<uint8_t>({'M'})));
EXPECT_TRUE(status.ok()); EXPECT_TRUE(status.ok());
...@@ -205,7 +203,7 @@ TEST(JsonStdStringWriterTest, BinaryEncodedAsJsonString) { ...@@ -205,7 +203,7 @@ TEST(JsonStdStringWriterTest, BinaryEncodedAsJsonString) {
{ // "Hello, world.", verified with base64decode.org. { // "Hello, world.", verified with base64decode.org.
std::string out; std::string out;
Status status; Status status;
std::unique_ptr<StreamingParserHandler> writer = std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status); NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleBinary(SpanFrom(std::vector<uint8_t>( writer->HandleBinary(SpanFrom(std::vector<uint8_t>(
{'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '.'}))); {'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '.'})));
...@@ -219,7 +217,7 @@ TEST(JsonStdStringWriterTest, HandlesErrors) { ...@@ -219,7 +217,7 @@ TEST(JsonStdStringWriterTest, HandlesErrors) {
// status and clears the output. // status and clears the output.
std::string out; std::string out;
Status status; Status status;
std::unique_ptr<StreamingParserHandler> writer = std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&GetTestPlatform(), &out, &status); NewJSONEncoder(&GetTestPlatform(), &out, &status);
writer->HandleMapBegin(); writer->HandleMapBegin();
WriteUTF8AsUTF16(writer.get(), "msg1"); WriteUTF8AsUTF16(writer.get(), "msg1");
...@@ -257,7 +255,7 @@ TEST(JsonStdStringWriterTest, DoubleToString) { ...@@ -257,7 +255,7 @@ TEST(JsonStdStringWriterTest, DoubleToString) {
std::string out; std::string out;
Status status; Status status;
std::unique_ptr<StreamingParserHandler> writer = std::unique_ptr<ParserHandler> writer =
NewJSONEncoder(&platform, &out, &status); NewJSONEncoder(&platform, &out, &status);
writer->HandleArrayBegin(); writer->HandleArrayBegin();
writer->HandleDouble(.1); writer->HandleDouble(.1);
...@@ -270,7 +268,7 @@ TEST(JsonStdStringWriterTest, DoubleToString) { ...@@ -270,7 +268,7 @@ TEST(JsonStdStringWriterTest, DoubleToString) {
// json::ParseJSON - for receiving streaming parser events for JSON // json::ParseJSON - for receiving streaming parser events for JSON
// ============================================================================= // =============================================================================
class Log : public StreamingParserHandler { class Log : public ParserHandler {
public: public:
void HandleMapBegin() override { log_ << "map begin\n"; } void HandleMapBegin() override { log_ << "map begin\n"; }
......
...@@ -5,16 +5,7 @@ ...@@ -5,16 +5,7 @@
#ifndef V8_CRDTP_PARSER_HANDLER_H_ #ifndef V8_CRDTP_PARSER_HANDLER_H_
#define V8_CRDTP_PARSER_HANDLER_H_ #define V8_CRDTP_PARSER_HANDLER_H_
#include <algorithm>
#include <cstddef>
#include <cstdint> #include <cstdint>
#include <cstring>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include "export.h"
#include "span.h" #include "span.h"
#include "status.h" #include "status.h"
...@@ -22,9 +13,9 @@ namespace v8_crdtp { ...@@ -22,9 +13,9 @@ namespace v8_crdtp {
// Handler interface for parser events emitted by a streaming parser. // Handler interface for parser events emitted by a streaming parser.
// See cbor::NewCBOREncoder, cbor::ParseCBOR, json::NewJSONEncoder, // See cbor::NewCBOREncoder, cbor::ParseCBOR, json::NewJSONEncoder,
// json::ParseJSON. // json::ParseJSON.
class StreamingParserHandler { class ParserHandler {
public: public:
virtual ~StreamingParserHandler() = default; virtual ~ParserHandler() = default;
virtual void HandleMapBegin() = 0; virtual void HandleMapBegin() = 0;
virtual void HandleMapEnd() = 0; virtual void HandleMapEnd() = 0;
virtual void HandleArrayBegin() = 0; virtual void HandleArrayBegin() = 0;
......
...@@ -6,16 +6,11 @@ ...@@ -6,16 +6,11 @@
#define V8_CRDTP_SPAN_H_ #define V8_CRDTP_SPAN_H_
#include <algorithm> #include <algorithm>
#include <cstddef>
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <limits>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include "export.h"
namespace v8_crdtp { namespace v8_crdtp {
// ============================================================================= // =============================================================================
// span - sequence of bytes // span - sequence of bytes
......
...@@ -2,22 +2,12 @@ ...@@ -2,22 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "span.h"
#include <array>
#include <clocale>
#include <cmath>
#include <cstdlib> #include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string> #include <string>
#include "span.h"
#include "test_platform.h" #include "test_platform.h"
using testing::ElementsAreArray;
namespace v8_crdtp { namespace v8_crdtp {
// ============================================================================= // =============================================================================
// span - sequence of bytes // span - sequence of bytes
......
...@@ -4,13 +4,6 @@ ...@@ -4,13 +4,6 @@
#include "status.h" #include "status.h"
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <limits>
#include <stack>
namespace v8_crdtp { namespace v8_crdtp {
// ============================================================================= // =============================================================================
// Status and Error codes // Status and Error codes
......
...@@ -2,17 +2,12 @@ ...@@ -2,17 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef V8_CRDTP_ENCODING_H_ #ifndef V8_CRDTP_STATUS_H_
#define V8_CRDTP_ENCODING_H_ #define V8_CRDTP_STATUS_H_
#include <algorithm>
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits> #include <limits>
#include <memory>
#include <string> #include <string>
#include <vector>
#include "export.h" #include "export.h"
...@@ -20,6 +15,7 @@ namespace v8_crdtp { ...@@ -20,6 +15,7 @@ namespace v8_crdtp {
// ============================================================================= // =============================================================================
// Status and Error codes // Status and Error codes
// ============================================================================= // =============================================================================
enum class Error { enum class Error {
OK = 0, OK = 0,
// JSON parsing errors - json_parser.{h,cc}. // JSON parsing errors - json_parser.{h,cc}.
...@@ -89,4 +85,4 @@ struct Status { ...@@ -89,4 +85,4 @@ struct Status {
}; };
} // namespace v8_crdtp } // namespace v8_crdtp
#endif // V8_CRDTP_ENCODING_H_ #endif // V8_CRDTP_STATUS_H_
...@@ -3,21 +3,8 @@ ...@@ -3,21 +3,8 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "status.h" #include "status.h"
#include <array>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include "test_platform.h" #include "test_platform.h"
using testing::ElementsAreArray;
namespace v8_crdtp { namespace v8_crdtp {
// ============================================================================= // =============================================================================
// Status and Error codes // Status and Error codes
......
...@@ -317,13 +317,12 @@ std::unique_ptr<Serializable> InternalResponse::createErrorResponse(int callId, ...@@ -317,13 +317,12 @@ std::unique_ptr<Serializable> InternalResponse::createErrorResponse(int callId,
void InternalResponse::AppendSerialized(std::vector<uint8_t>* out) const void InternalResponse::AppendSerialized(std::vector<uint8_t>* out) const
{ {
using {{config.crdtp.namespace}}::cbor::NewCBOREncoder; using {{config.crdtp.namespace}}::cbor::NewCBOREncoder;
using {{config.crdtp.namespace}}::StreamingParserHandler; using {{config.crdtp.namespace}}::ParserHandler;
using {{config.crdtp.namespace}}::Status; using {{config.crdtp.namespace}}::Status;
using {{config.crdtp.namespace}}::SpanFrom; using {{config.crdtp.namespace}}::SpanFrom;
Status status; Status status;
std::unique_ptr<StreamingParserHandler> encoder = std::unique_ptr<ParserHandler> encoder = NewCBOREncoder(out, &status);
NewCBOREncoder(out, &status);
encoder->HandleMapBegin(); encoder->HandleMapBegin();
if (m_method) { if (m_method) {
encoder->HandleString8(SpanFrom("method")); encoder->HandleString8(SpanFrom("method"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment