diff options
Diffstat (limited to 'deps/v8/third_party/inspector_protocol/encoding/encoding.h')
-rw-r--r-- | deps/v8/third_party/inspector_protocol/encoding/encoding.h | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/deps/v8/third_party/inspector_protocol/encoding/encoding.h b/deps/v8/third_party/inspector_protocol/encoding/encoding.h index 90916d42b3..340667f604 100644 --- a/deps/v8/third_party/inspector_protocol/encoding/encoding.h +++ b/deps/v8/third_party/inspector_protocol/encoding/encoding.h @@ -5,6 +5,7 @@ #ifndef V8_INSPECTOR_PROTOCOL_ENCODING_ENCODING_H_ #define V8_INSPECTOR_PROTOCOL_ENCODING_ENCODING_H_ +#include <algorithm> #include <cstddef> #include <cstdint> #include <cstring> @@ -14,6 +15,19 @@ #include <vector> namespace v8_inspector_protocol_encoding { +// This library is designed to be portable. The only allowed dependency +// are the C/C++ standard libraries, up to C++11. We support both 32 bit +// and 64 architectures. +// +// Types used below: +// uint8_t: a byte, e.g. for raw bytes or UTF8 characters +// uint16_t: two bytes, e.g. for UTF16 characters +// For input parameters: +// span<uint8_t>: pointer to bytes and length +// span<uint16_t>: pointer to UTF16 chars and length +// For output parameters: +// std::vector<uint8_t> - Owned segment of bytes / utf8 characters and length. +// std::string - Same, for compatibility, even though char is signed. // ============================================================================= // span - sequence of bytes @@ -72,6 +86,22 @@ inline span<uint8_t> SpanFrom(const std::string& v) { return span<uint8_t>(reinterpret_cast<const uint8_t*>(v.data()), v.size()); } +// Less than / equality comparison functions for sorting / searching for byte +// spans. These are similar to absl::string_view's < and == operators. +inline bool SpanLessThan(span<uint8_t> x, span<uint8_t> y) noexcept { + auto min_size = std::min(x.size(), y.size()); + const int r = min_size == 0 ? 0 : memcmp(x.data(), y.data(), min_size); + return (r < 0) || (r == 0 && x.size() < y.size()); +} + +inline bool SpanEquals(span<uint8_t> x, span<uint8_t> y) noexcept { + auto len = x.size(); + if (len != y.size()) + return false; + return x.data() == y.data() || len == 0 || + std::memcmp(x.data(), y.data(), len) == 0; +} + // ============================================================================= // Status and Error codes // ============================================================================= @@ -427,7 +457,7 @@ Status AppendString8EntryToCBORMap(span<uint8_t> string8_key, std::string* cbor); namespace internals { // Exposed only for writing tests. -int8_t ReadTokenStart(span<uint8_t> bytes, +size_t ReadTokenStart(span<uint8_t> bytes, cbor::MajorType* type, uint64_t* value); |