diff options
Diffstat (limited to 'tools/inspector_protocol/lib/base_string_adapter_cc.template')
-rw-r--r-- | tools/inspector_protocol/lib/base_string_adapter_cc.template | 78 |
1 files changed, 8 insertions, 70 deletions
diff --git a/tools/inspector_protocol/lib/base_string_adapter_cc.template b/tools/inspector_protocol/lib/base_string_adapter_cc.template index ed3316446f..639b39bb52 100644 --- a/tools/inspector_protocol/lib/base_string_adapter_cc.template +++ b/tools/inspector_protocol/lib/base_string_adapter_cc.template @@ -136,7 +136,7 @@ std::unique_ptr<Value> StringUtil::parseMessage( reinterpret_cast<const uint8_t*>(message.data()), message.length()); } - std::unique_ptr<base::Value> value = base::JSONReader::Read(message); + std::unique_ptr<base::Value> value = base::JSONReader::ReadDeprecated(message); return toProtocolValue(value.get(), 1000); } @@ -185,6 +185,13 @@ void StringBuilder::reserveCapacity(size_t capacity) { string_.reserve(capacity); } +// static +String StringUtil::fromUTF16(const uint16_t* data, size_t length) { + std::string utf8; + base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(data), length, &utf8); + return utf8; +} + Binary::Binary() : bytes_(new base::RefCountedBytes) {} Binary::Binary(const Binary& binary) : bytes_(binary.bytes_) {} Binary::Binary(scoped_refptr<base::RefCountedMemory> bytes) : bytes_(bytes) {} @@ -230,75 +237,6 @@ Binary Binary::fromSpan(const uint8_t* data, size_t size) { new base::RefCountedBytes(data, size))); } -namespace { -int32_t ReadEnvelopeSize(const uint8_t* in) { - return (in[0] << 24) + (in[1] << 16) + (in[2] << 8) + in[3]; -} - -void WriteEnvelopeSize(uint32_t value, uint8_t* out) { - *(out++) = (value >> 24) & 0xFF; - *(out++) = (value >> 16) & 0xFF; - *(out++) = (value >> 8) & 0xFF; - *(out++) = (value) & 0xFF; -} - -} - -bool AppendStringValueToMapBinary(base::StringPiece in, - base::StringPiece key, base::StringPiece value, std::string* out) { - if (in.size() < 1 + 1 + 4 + 1 + 1) - return false; - const uint8_t* envelope = reinterpret_cast<const uint8_t*>(in.data()); - if (cbor::kInitialByteForEnvelope != envelope[0]) - return false; - if (cbor::kInitialByteFor32BitLengthByteString != envelope[1]) - return false; - if (cbor::kInitialByteIndefiniteLengthMap != envelope[6]) - return false; - - uint32_t envelope_size = ReadEnvelopeSize(envelope + 2); - if (envelope_size + 2 + 4 != in.size()) - return false; - if (cbor::kStopByte != static_cast<uint8_t>(*in.rbegin())) - return false; - - std::vector<uint8_t> encoded_entry; - encoded_entry.reserve(1 + 4 + key.size() + 1 + 4 + value.size()); - span<uint8_t> key_span( - reinterpret_cast<const uint8_t*>(key.data()), key.size()); - EncodeString8(key_span, &encoded_entry); - span<uint8_t> value_span( - reinterpret_cast<const uint8_t*>(value.data()), value.size()); - EncodeString8(value_span, &encoded_entry); - - out->clear(); - out->reserve(in.size() + encoded_entry.size()); - out->append(in.begin(), in.end() - 1); - out->append(reinterpret_cast<const char*>(encoded_entry.data()), - encoded_entry.size()); - out->append(1, static_cast<char>(cbor::kStopByte)); - std::size_t new_size = envelope_size + out->size() - in.size(); - if (new_size > static_cast<std::size_t>( - std::numeric_limits<uint32_t>::max())) { - return false; - } - WriteEnvelopeSize(new_size, reinterpret_cast<uint8_t*>(&*out->begin() + 2)); - return true; -} - -bool AppendStringValueToMapJSON(base::StringPiece in, - base::StringPiece key, base::StringPiece value, std::string* out) { - if (!in.length() || *in.rbegin() != '}') - return false; - std::string suffix = - base::StringPrintf(", \"%s\": \"%s\"}", key.begin(), value.begin()); - out->clear(); - out->reserve(in.length() + suffix.length() - 1); - out->append(in.data(), in.length() - 1); - out->append(suffix); - return true; -} - {% for namespace in config.protocol.namespace %} } // namespace {{namespace}} {% endfor %} |