Commit 2633923a authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

Roll inspector_protocol to e1991e6a66f0519e48e9e2c93efff15d62c3b2ca.

- This adds the CBOR template impl.

Change-Id: Iff3854e4dda2e912518a96fd21739f0882eca544
Reviewed-on: https://chromium-review.googlesource.com/c/1461300Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630557}
parent 4114ecdd
...@@ -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: dfaf19b7350529d9d454ae79b6747ee57cd1c6d4 Revision: e1991e6a66f0519e48e9e2c93efff15d62c3b2ca
License: BSD License: BSD
License File: LICENSE License File: LICENSE
Security Critical: no Security Critical: no
......
...@@ -245,12 +245,12 @@ void EncodeBinary(span<uint8_t> in, std::vector<uint8_t>* out) { ...@@ -245,12 +245,12 @@ void EncodeBinary(span<uint8_t> in, std::vector<uint8_t>* out) {
// A double is encoded with a specific initial byte // A double is encoded with a specific initial byte
// (kInitialByteForDouble) plus the 64 bits of payload for its value. // (kInitialByteForDouble) plus the 64 bits of payload for its value.
constexpr int kEncodedDoubleSize = 1 + sizeof(uint64_t); constexpr std::ptrdiff_t kEncodedDoubleSize = 1 + sizeof(uint64_t);
// An envelope is encoded with a specific initial byte // An envelope is encoded with a specific initial byte
// (kInitialByteForEnvelope), plus the start byte for a BYTE_STRING with a 32 // (kInitialByteForEnvelope), plus the start byte for a BYTE_STRING with a 32
// bit wide length, plus a 32 bit length for that string. // bit wide length, plus a 32 bit length for that string.
constexpr int kEncodedEnvelopeHeaderSize = 1 + 1 + sizeof(uint32_t); constexpr std::ptrdiff_t kEncodedEnvelopeHeaderSize = 1 + 1 + sizeof(uint32_t);
void EncodeDouble(double value, std::vector<uint8_t>* out) { void EncodeDouble(double value, std::vector<uint8_t>* out) {
// The additional_info=27 indicates 64 bits for the double follow. // The additional_info=27 indicates 64 bits for the double follow.
...@@ -606,23 +606,20 @@ double CBORTokenizer::GetDouble() const { ...@@ -606,23 +606,20 @@ double CBORTokenizer::GetDouble() const {
span<uint8_t> CBORTokenizer::GetString8() const { span<uint8_t> CBORTokenizer::GetString8() const {
assert(token_tag_ == CBORTokenTag::STRING8); assert(token_tag_ == CBORTokenTag::STRING8);
return bytes_.subspan( auto length = static_cast<std::ptrdiff_t>(token_start_internal_value_);
status_.pos + (token_byte_length_ - token_start_internal_value_), return bytes_.subspan(status_.pos + (token_byte_length_ - length), length);
token_start_internal_value_);
} }
span<uint8_t> CBORTokenizer::GetString16WireRep() const { span<uint8_t> CBORTokenizer::GetString16WireRep() const {
assert(token_tag_ == CBORTokenTag::STRING16); assert(token_tag_ == CBORTokenTag::STRING16);
return bytes_.subspan( auto length = static_cast<std::ptrdiff_t>(token_start_internal_value_);
status_.pos + (token_byte_length_ - token_start_internal_value_), return bytes_.subspan(status_.pos + (token_byte_length_ - length), length);
token_start_internal_value_);
} }
span<uint8_t> CBORTokenizer::GetBinary() const { span<uint8_t> CBORTokenizer::GetBinary() const {
assert(token_tag_ == CBORTokenTag::BINARY); assert(token_tag_ == CBORTokenTag::BINARY);
return bytes_.subspan( auto length = static_cast<std::ptrdiff_t>(token_start_internal_value_);
status_.pos + (token_byte_length_ - token_start_internal_value_), return bytes_.subspan(status_.pos + (token_byte_length_ - length), length);
token_start_internal_value_);
} }
void CBORTokenizer::ReadNextToken(bool enter_envelope) { void CBORTokenizer::ReadNextToken(bool enter_envelope) {
...@@ -657,7 +654,7 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) { ...@@ -657,7 +654,7 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) {
SetToken(CBORTokenTag::NULL_VALUE, 1); SetToken(CBORTokenTag::NULL_VALUE, 1);
return; return;
case kExpectedConversionToBase64Tag: { // BINARY case kExpectedConversionToBase64Tag: { // BINARY
int64_t bytes_read = int8_t bytes_read =
ReadTokenStart(bytes_.subspan(status_.pos + 1), &token_start_type_, ReadTokenStart(bytes_.subspan(status_.pos + 1), &token_start_type_,
&token_start_internal_value_); &token_start_internal_value_);
int64_t token_byte_length = 1 + bytes_read + token_start_internal_value_; int64_t token_byte_length = 1 + bytes_read + token_start_internal_value_;
...@@ -666,7 +663,7 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) { ...@@ -666,7 +663,7 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) {
SetError(Error::CBOR_INVALID_BINARY); SetError(Error::CBOR_INVALID_BINARY);
return; return;
} }
SetToken(CBORTokenTag::BINARY, token_byte_length); SetToken(CBORTokenTag::BINARY, std::ptrdiff_t(token_byte_length));
return; return;
} }
case kInitialByteForDouble: { // DOUBLE case kInitialByteForDouble: { // DOUBLE
...@@ -697,16 +694,17 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) { ...@@ -697,16 +694,17 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) {
SetError(Error::CBOR_INVALID_ENVELOPE); SetError(Error::CBOR_INVALID_ENVELOPE);
return; return;
} }
auto length = static_cast<std::ptrdiff_t>(token_start_internal_value_);
SetToken(CBORTokenTag::ENVELOPE, SetToken(CBORTokenTag::ENVELOPE,
kEncodedEnvelopeHeaderSize + token_start_internal_value_); kEncodedEnvelopeHeaderSize + length);
return; return;
} }
default: { default: {
span<uint8_t> remainder = span<uint8_t> remainder =
bytes_.subspan(status_.pos, bytes_.size() - status_.pos); bytes_.subspan(status_.pos, bytes_.size() - status_.pos);
assert(!remainder.empty()); assert(!remainder.empty());
int64_t token_start_length = ReadTokenStart(remainder, &token_start_type_, int8_t token_start_length = ReadTokenStart(remainder, &token_start_type_,
&token_start_internal_value_); &token_start_internal_value_);
bool success = token_start_length != -1; bool success = token_start_length != -1;
switch (token_start_type_) { switch (token_start_type_) {
case MajorType::UNSIGNED: // INT32. case MajorType::UNSIGNED: // INT32.
...@@ -726,16 +724,17 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) { ...@@ -726,16 +724,17 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) {
} }
SetToken(CBORTokenTag::INT32, token_start_length); SetToken(CBORTokenTag::INT32, token_start_length);
return; return;
case MajorType::STRING: // STRING8. case MajorType::STRING: { // STRING8.
if (!success || if (!success ||
remainder.size() < int64_t(token_start_internal_value_)) { remainder.size() < int64_t(token_start_internal_value_)) {
SetError(Error::CBOR_INVALID_STRING8); SetError(Error::CBOR_INVALID_STRING8);
return; return;
} }
SetToken(CBORTokenTag::STRING8, auto length = static_cast<std::ptrdiff_t>(token_start_internal_value_);
token_start_length + token_start_internal_value_); SetToken(CBORTokenTag::STRING8, token_start_length + length);
return; return;
case MajorType::BYTE_STRING: // STRING16. }
case MajorType::BYTE_STRING: { // STRING16.
if (!success || if (!success ||
remainder.size() < int64_t(token_start_internal_value_) || remainder.size() < int64_t(token_start_internal_value_) ||
// Must be divisible by 2 since UTF16 is 2 bytes per character. // Must be divisible by 2 since UTF16 is 2 bytes per character.
...@@ -743,9 +742,10 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) { ...@@ -743,9 +742,10 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) {
SetError(Error::CBOR_INVALID_STRING16); SetError(Error::CBOR_INVALID_STRING16);
return; return;
} }
SetToken(CBORTokenTag::STRING16, auto length = static_cast<std::ptrdiff_t>(token_start_internal_value_);
token_start_length + token_start_internal_value_); SetToken(CBORTokenTag::STRING16, token_start_length + length);
return; return;
}
case MajorType::ARRAY: case MajorType::ARRAY:
case MajorType::MAP: case MajorType::MAP:
case MajorType::TAG: case MajorType::TAG:
...@@ -758,7 +758,7 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) { ...@@ -758,7 +758,7 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) {
} }
void CBORTokenizer::SetToken(CBORTokenTag token_tag, void CBORTokenizer::SetToken(CBORTokenTag token_tag,
int64_t token_byte_length) { std::ptrdiff_t token_byte_length) {
token_tag_ = token_tag; token_tag_ = token_tag;
token_byte_length_ = token_byte_length; token_byte_length_ = token_byte_length;
} }
......
...@@ -82,7 +82,7 @@ class EnvelopeEncoder { ...@@ -82,7 +82,7 @@ class EnvelopeEncoder {
bool EncodeStop(std::vector<uint8_t>* out); bool EncodeStop(std::vector<uint8_t>* out);
private: private:
uint64_t byte_size_pos_ = 0; std::vector<uint8_t>::size_type byte_size_pos_ = 0;
}; };
// This can be used to convert from JSON to CBOR, by passing the // This can be used to convert from JSON to CBOR, by passing the
...@@ -186,13 +186,13 @@ class CBORTokenizer { ...@@ -186,13 +186,13 @@ class CBORTokenizer {
private: private:
void ReadNextToken(bool enter_envelope); void ReadNextToken(bool enter_envelope);
void SetToken(CBORTokenTag token, int64_t token_byte_length); void SetToken(CBORTokenTag token, std::ptrdiff_t token_byte_length);
void SetError(Error error); void SetError(Error error);
span<uint8_t> bytes_; span<uint8_t> bytes_;
CBORTokenTag token_tag_; CBORTokenTag token_tag_;
struct Status status_; struct Status status_;
int64_t token_byte_length_; std::ptrdiff_t token_byte_length_;
cbor_internals::MajorType token_start_type_; cbor_internals::MajorType token_start_type_;
uint64_t token_start_internal_value_; uint64_t token_start_internal_value_;
}; };
......
...@@ -573,13 +573,13 @@ class JsonParser { ...@@ -573,13 +573,13 @@ class JsonParser {
void ParseJSONChars(const Platform* platform, span<uint8_t> chars, void ParseJSONChars(const Platform* platform, span<uint8_t> chars,
JSONParserHandler* handler) { JSONParserHandler* handler) {
JsonParser<uint8_t> parser(platform, handler); JsonParser<uint8_t> parser(deps, handler);
parser.Parse(chars.data(), chars.size()); parser.Parse(chars.data(), chars.size());
} }
void ParseJSONChars(const Platform* platform, span<uint16_t> chars, void ParseJSONChars(const Platform* platform, span<uint16_t> chars,
JSONParserHandler* handler) { JSONParserHandler* handler) {
JsonParser<uint16_t> parser(platform, handler); JsonParser<uint16_t> parser(deps, handler);
parser.Parse(chars.data(), chars.size()); parser.Parse(chars.data(), chars.size());
} }
} // namespace inspector_protocol } // namespace inspector_protocol
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
namespace inspector_protocol { namespace inspector_protocol {
// JSON parsing routines. // JSON parsing routines.
void ParseJSONChars(const Platform* deps, span<uint8_t> chars, void ParseJSONChars(const Platform* platform, span<uint8_t> chars,
JSONParserHandler* handler); JSONParserHandler* handler);
void ParseJSONChars(const Platform* deps, span<uint16_t> chars, void ParseJSONChars(const Platform* platform, span<uint16_t> chars,
JSONParserHandler* handler); JSONParserHandler* handler);
} // namespace inspector_protocol } // namespace inspector_protocol
......
...@@ -48,12 +48,12 @@ enum class Error { ...@@ -48,12 +48,12 @@ enum class Error {
// A status value with position that can be copied. The default status // A status value with position that can be copied. The default status
// is OK. Usually, error status values should come with a valid position. // is OK. Usually, error status values should come with a valid position.
struct Status { struct Status {
static constexpr int64_t npos() { return -1; } static constexpr std::ptrdiff_t npos() { return -1; }
bool ok() const { return error == Error::OK; } bool ok() const { return error == Error::OK; }
Error error = Error::OK; Error error = Error::OK;
int64_t pos = npos(); std::ptrdiff_t pos = npos();
}; };
} // namespace inspector_protocol } // namespace inspector_protocol
#endif // INSPECTOR_PROTOCOL_ENCODING_STATUS_H_ #endif // INSPECTOR_PROTOCOL_ENCODING_STATUS_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "str_util.h"
#include <cstring>
namespace inspector_protocol {
bool StrEq(span<uint8_t> left, span<uint8_t> right) {
return left.size() == right.size() &&
0 == memcmp(left.data(), right.data(), left.size());
}
bool StrEq(span<uint8_t> left, const char* null_terminated_right) {
return size_t(left.size()) == strlen(null_terminated_right) &&
0 == memcmp(left.data(), null_terminated_right, left.size());
}
} // namespace inspector_protocol
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef INSPECTOR_PROTOCOL_ENCODING_STR_UTIL_H_
#define INSPECTOR_PROTOCOL_ENCODING_STR_UTIL_H_
#include <cstdint>
#include "span.h"
namespace inspector_protocol {
// Returns true iff |left| and right have the same contents, byte for byte.
bool StrEq(span<uint8_t> left, span<uint8_t> right);
bool StrEq(span<uint8_t> left, const char* null_terminated_right);
} // namespace inspector_protocol
#endif // INSPECTOR_PROTOCOL_ENCODING_STR_UTIL_H_
...@@ -35,6 +35,8 @@ template("inspector_protocol_generate") { ...@@ -35,6 +35,8 @@ template("inspector_protocol_generate") {
"$inspector_protocol_dir/lib/base_string_adapter_h.template", "$inspector_protocol_dir/lib/base_string_adapter_h.template",
"$inspector_protocol_dir/lib/Allocator_h.template", "$inspector_protocol_dir/lib/Allocator_h.template",
"$inspector_protocol_dir/lib/Array_h.template", "$inspector_protocol_dir/lib/Array_h.template",
"$inspector_protocol_dir/lib/CBOR_h.template",
"$inspector_protocol_dir/lib/CBOR_cpp.template",
"$inspector_protocol_dir/lib/DispatcherBase_cpp.template", "$inspector_protocol_dir/lib/DispatcherBase_cpp.template",
"$inspector_protocol_dir/lib/DispatcherBase_h.template", "$inspector_protocol_dir/lib/DispatcherBase_h.template",
"$inspector_protocol_dir/lib/ErrorSupport_cpp.template", "$inspector_protocol_dir/lib/ErrorSupport_cpp.template",
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
'inspector_protocol_files': [ 'inspector_protocol_files': [
'lib/Allocator_h.template', 'lib/Allocator_h.template',
'lib/Array_h.template', 'lib/Array_h.template',
'lib/CBOR_h.template',
'lib/CBOR_cpp.template',
'lib/DispatcherBase_cpp.template', 'lib/DispatcherBase_cpp.template',
'lib/DispatcherBase_h.template', 'lib/DispatcherBase_h.template',
'lib/ErrorSupport_cpp.template', 'lib/ErrorSupport_cpp.template',
......
This diff is collapsed.
This diff is collapsed.
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
// 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 {{"_".join(config.protocol.namespace)}}_Parser_h #ifndef {{"_".join(config.protocol.namespace)}}_BASE_STRING_ADAPTER_H
#define {{"_".join(config.protocol.namespace)}}_Parser_h #define {{"_".join(config.protocol.namespace)}}_BASE_STRING_ADAPTER_H
#include <memory> #include <memory>
#include <string> #include <string>
...@@ -123,4 +123,4 @@ std::unique_ptr<base::Value> toBaseValue(Value* value, int depth); ...@@ -123,4 +123,4 @@ std::unique_ptr<base::Value> toBaseValue(Value* value, int depth);
} // namespace {{namespace}} } // namespace {{namespace}}
{% endfor %} {% endfor %}
#endif // !defined({{"_".join(config.protocol.namespace)}}_Parser_h) #endif // !defined({{"_".join(config.protocol.namespace)}}_BASE_STRING_ADAPTER_H)
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