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
Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0
Revision: dfaf19b7350529d9d454ae79b6747ee57cd1c6d4
Revision: e1991e6a66f0519e48e9e2c93efff15d62c3b2ca
License: BSD
License File: LICENSE
Security Critical: no
......
......@@ -245,12 +245,12 @@ void EncodeBinary(span<uint8_t> in, std::vector<uint8_t>* out) {
// A double is encoded with a specific initial byte
// (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
// (kInitialByteForEnvelope), plus the start byte for a BYTE_STRING with a 32
// 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) {
// The additional_info=27 indicates 64 bits for the double follow.
......@@ -606,23 +606,20 @@ double CBORTokenizer::GetDouble() const {
span<uint8_t> CBORTokenizer::GetString8() const {
assert(token_tag_ == CBORTokenTag::STRING8);
return bytes_.subspan(
status_.pos + (token_byte_length_ - token_start_internal_value_),
token_start_internal_value_);
auto length = static_cast<std::ptrdiff_t>(token_start_internal_value_);
return bytes_.subspan(status_.pos + (token_byte_length_ - length), length);
}
span<uint8_t> CBORTokenizer::GetString16WireRep() const {
assert(token_tag_ == CBORTokenTag::STRING16);
return bytes_.subspan(
status_.pos + (token_byte_length_ - token_start_internal_value_),
token_start_internal_value_);
auto length = static_cast<std::ptrdiff_t>(token_start_internal_value_);
return bytes_.subspan(status_.pos + (token_byte_length_ - length), length);
}
span<uint8_t> CBORTokenizer::GetBinary() const {
assert(token_tag_ == CBORTokenTag::BINARY);
return bytes_.subspan(
status_.pos + (token_byte_length_ - token_start_internal_value_),
token_start_internal_value_);
auto length = static_cast<std::ptrdiff_t>(token_start_internal_value_);
return bytes_.subspan(status_.pos + (token_byte_length_ - length), length);
}
void CBORTokenizer::ReadNextToken(bool enter_envelope) {
......@@ -657,7 +654,7 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) {
SetToken(CBORTokenTag::NULL_VALUE, 1);
return;
case kExpectedConversionToBase64Tag: { // BINARY
int64_t bytes_read =
int8_t bytes_read =
ReadTokenStart(bytes_.subspan(status_.pos + 1), &token_start_type_,
&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) {
SetError(Error::CBOR_INVALID_BINARY);
return;
}
SetToken(CBORTokenTag::BINARY, token_byte_length);
SetToken(CBORTokenTag::BINARY, std::ptrdiff_t(token_byte_length));
return;
}
case kInitialByteForDouble: { // DOUBLE
......@@ -697,16 +694,17 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) {
SetError(Error::CBOR_INVALID_ENVELOPE);
return;
}
auto length = static_cast<std::ptrdiff_t>(token_start_internal_value_);
SetToken(CBORTokenTag::ENVELOPE,
kEncodedEnvelopeHeaderSize + token_start_internal_value_);
kEncodedEnvelopeHeaderSize + length);
return;
}
default: {
span<uint8_t> remainder =
bytes_.subspan(status_.pos, bytes_.size() - status_.pos);
assert(!remainder.empty());
int64_t token_start_length = ReadTokenStart(remainder, &token_start_type_,
&token_start_internal_value_);
int8_t token_start_length = ReadTokenStart(remainder, &token_start_type_,
&token_start_internal_value_);
bool success = token_start_length != -1;
switch (token_start_type_) {
case MajorType::UNSIGNED: // INT32.
......@@ -726,16 +724,17 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) {
}
SetToken(CBORTokenTag::INT32, token_start_length);
return;
case MajorType::STRING: // STRING8.
case MajorType::STRING: { // STRING8.
if (!success ||
remainder.size() < int64_t(token_start_internal_value_)) {
SetError(Error::CBOR_INVALID_STRING8);
return;
}
SetToken(CBORTokenTag::STRING8,
token_start_length + token_start_internal_value_);
auto length = static_cast<std::ptrdiff_t>(token_start_internal_value_);
SetToken(CBORTokenTag::STRING8, token_start_length + length);
return;
case MajorType::BYTE_STRING: // STRING16.
}
case MajorType::BYTE_STRING: { // STRING16.
if (!success ||
remainder.size() < int64_t(token_start_internal_value_) ||
// Must be divisible by 2 since UTF16 is 2 bytes per character.
......@@ -743,9 +742,10 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) {
SetError(Error::CBOR_INVALID_STRING16);
return;
}
SetToken(CBORTokenTag::STRING16,
token_start_length + token_start_internal_value_);
auto length = static_cast<std::ptrdiff_t>(token_start_internal_value_);
SetToken(CBORTokenTag::STRING16, token_start_length + length);
return;
}
case MajorType::ARRAY:
case MajorType::MAP:
case MajorType::TAG:
......@@ -758,7 +758,7 @@ void CBORTokenizer::ReadNextToken(bool enter_envelope) {
}
void CBORTokenizer::SetToken(CBORTokenTag token_tag,
int64_t token_byte_length) {
std::ptrdiff_t token_byte_length) {
token_tag_ = token_tag;
token_byte_length_ = token_byte_length;
}
......
......@@ -82,7 +82,7 @@ class EnvelopeEncoder {
bool EncodeStop(std::vector<uint8_t>* out);
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
......@@ -186,13 +186,13 @@ class CBORTokenizer {
private:
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);
span<uint8_t> bytes_;
CBORTokenTag token_tag_;
struct Status status_;
int64_t token_byte_length_;
std::ptrdiff_t token_byte_length_;
cbor_internals::MajorType token_start_type_;
uint64_t token_start_internal_value_;
};
......
......@@ -573,13 +573,13 @@ class JsonParser {
void ParseJSONChars(const Platform* platform, span<uint8_t> chars,
JSONParserHandler* handler) {
JsonParser<uint8_t> parser(platform, handler);
JsonParser<uint8_t> parser(deps, handler);
parser.Parse(chars.data(), chars.size());
}
void ParseJSONChars(const Platform* platform, span<uint16_t> chars,
JSONParserHandler* handler) {
JsonParser<uint16_t> parser(platform, handler);
JsonParser<uint16_t> parser(deps, handler);
parser.Parse(chars.data(), chars.size());
}
} // namespace inspector_protocol
......@@ -13,9 +13,9 @@
namespace inspector_protocol {
// JSON parsing routines.
void ParseJSONChars(const Platform* deps, span<uint8_t> chars,
void ParseJSONChars(const Platform* platform, span<uint8_t> chars,
JSONParserHandler* handler);
void ParseJSONChars(const Platform* deps, span<uint16_t> chars,
void ParseJSONChars(const Platform* platform, span<uint16_t> chars,
JSONParserHandler* handler);
} // namespace inspector_protocol
......
......@@ -48,12 +48,12 @@ enum class Error {
// A status value with position that can be copied. The default status
// is OK. Usually, error status values should come with a valid position.
struct Status {
static constexpr int64_t npos() { return -1; }
static constexpr std::ptrdiff_t npos() { return -1; }
bool ok() const { return error == Error::OK; }
Error error = Error::OK;
int64_t pos = npos();
std::ptrdiff_t pos = npos();
};
} // namespace inspector_protocol
#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") {
"$inspector_protocol_dir/lib/base_string_adapter_h.template",
"$inspector_protocol_dir/lib/Allocator_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_h.template",
"$inspector_protocol_dir/lib/ErrorSupport_cpp.template",
......
......@@ -7,6 +7,8 @@
'inspector_protocol_files': [
'lib/Allocator_h.template',
'lib/Array_h.template',
'lib/CBOR_h.template',
'lib/CBOR_cpp.template',
'lib/DispatcherBase_cpp.template',
'lib/DispatcherBase_h.template',
'lib/ErrorSupport_cpp.template',
......
This diff is collapsed.
This diff is collapsed.
......@@ -4,8 +4,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef {{"_".join(config.protocol.namespace)}}_Parser_h
#define {{"_".join(config.protocol.namespace)}}_Parser_h
#ifndef {{"_".join(config.protocol.namespace)}}_BASE_STRING_ADAPTER_H
#define {{"_".join(config.protocol.namespace)}}_BASE_STRING_ADAPTER_H
#include <memory>
#include <string>
......@@ -123,4 +123,4 @@ std::unique_ptr<base::Value> toBaseValue(Value* value, int depth);
} // namespace {{namespace}}
{% 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