LCOV - code coverage report
Current view: top level - out/Release/gen/src/inspector/protocol - Protocol.h (source / functions) Hit Total Coverage
Test: app.info Lines: 122 165 73.9 %
Date: 2019-02-19 Functions: 55 95 57.9 %

          Line data    Source code
       1             : // This file is generated by ErrorSupport_h.template.
       2             : 
       3             : // Copyright 2016 The Chromium Authors. All rights reserved.
       4             : // Use of this source code is governed by a BSD-style license that can be
       5             : // found in the LICENSE file.
       6             : 
       7             : #ifndef v8_inspector_protocol_ErrorSupport_h
       8             : #define v8_inspector_protocol_ErrorSupport_h
       9             : 
      10             : #include "src/inspector/protocol/Forward.h"
      11             : 
      12             : namespace v8_inspector {
      13             : namespace protocol {
      14             : 
      15             : class  ErrorSupport {
      16             : public:
      17             :     ErrorSupport();
      18             :     ~ErrorSupport();
      19             : 
      20             :     void push();
      21             :     void setName(const char*);
      22             :     void setName(const String&);
      23             :     void pop();
      24             :     void addError(const char*);
      25             :     void addError(const String&);
      26             :     bool hasErrors();
      27             :     String errors();
      28             : 
      29             : private:
      30             :     std::vector<String> m_path;
      31             :     std::vector<String> m_errors;
      32             : };
      33             : 
      34             : } // namespace v8_inspector
      35             : } // namespace protocol
      36             : 
      37             : #endif // !defined(v8_inspector_protocol_ErrorSupport_h)
      38             : 
      39             : 
      40             : // This file is generated by Values_h.template.
      41             : 
      42             : // Copyright 2016 The Chromium Authors. All rights reserved.
      43             : // Use of this source code is governed by a BSD-style license that can be
      44             : // found in the LICENSE file.
      45             : 
      46             : #ifndef v8_inspector_protocol_Values_h
      47             : #define v8_inspector_protocol_Values_h
      48             : 
      49             : //#include "Allocator.h"
      50             : //#include "Forward.h"
      51             : 
      52             : namespace v8_inspector {
      53             : namespace protocol {
      54             : 
      55             : class ListValue;
      56             : class DictionaryValue;
      57             : class Value;
      58             : 
      59             : class  Value : public Serializable {
      60             :     PROTOCOL_DISALLOW_COPY(Value);
      61             : public:
      62    38582208 :     virtual ~Value() override { }
      63             : 
      64             :     static std::unique_ptr<Value> null()
      65             :     {
      66        5339 :         return std::unique_ptr<Value>(new Value());
      67             :     }
      68             : 
      69             :     static std::unique_ptr<Value> parseBinary(const uint8_t* data, size_t size);
      70             : 
      71             :     enum ValueType {
      72             :         TypeNull = 0,
      73             :         TypeBoolean,
      74             :         TypeInteger,
      75             :         TypeDouble,
      76             :         TypeString,
      77             :         TypeBinary,
      78             :         TypeObject,
      79             :         TypeArray,
      80             :         TypeSerialized,
      81             :         TypeImported
      82             :     };
      83             : 
      84             :     ValueType type() const { return m_type; }
      85             : 
      86             :     bool isNull() const { return m_type == TypeNull; }
      87             : 
      88             :     virtual bool asBoolean(bool* output) const;
      89             :     virtual bool asDouble(double* output) const;
      90             :     virtual bool asInteger(int* output) const;
      91             :     virtual bool asString(String* output) const;
      92             :     virtual bool asBinary(Binary* output) const;
      93             : 
      94             :     virtual void writeJSON(StringBuilder* output) const;
      95             :     virtual void writeBinary(std::vector<uint8_t>* bytes) const;
      96             :     virtual std::unique_ptr<Value> clone() const;
      97             :     String toJSONString() const;
      98             :     String serializeToJSON() override;
      99             :     std::vector<uint8_t> serializeToBinary() override;
     100             : 
     101             : protected:
     102        5339 :     Value() : m_type(TypeNull) { }
     103    38571530 :     explicit Value(ValueType type) : m_type(type) { }
     104             : 
     105             : private:
     106             :     friend class DictionaryValue;
     107             :     friend class ListValue;
     108             : 
     109             :     ValueType m_type;
     110             : };
     111             : 
     112    25857824 : class  FundamentalValue : public Value {
     113             : public:
     114    10365126 :     static std::unique_ptr<FundamentalValue> create(bool value)
     115             :     {
     116    20730252 :         return std::unique_ptr<FundamentalValue>(new FundamentalValue(value));
     117             :     }
     118             : 
     119     2267818 :     static std::unique_ptr<FundamentalValue> create(int value)
     120             :     {
     121     4535636 :         return std::unique_ptr<FundamentalValue>(new FundamentalValue(value));
     122             :     }
     123             : 
     124      295968 :     static std::unique_ptr<FundamentalValue> create(double value)
     125             :     {
     126      591936 :         return std::unique_ptr<FundamentalValue>(new FundamentalValue(value));
     127             :     }
     128             : 
     129             :     bool asBoolean(bool* output) const override;
     130             :     bool asDouble(double* output) const override;
     131             :     bool asInteger(int* output) const override;
     132             :     void writeJSON(StringBuilder* output) const override;
     133             :     void writeBinary(std::vector<uint8_t>* bytes) const override;
     134             :     std::unique_ptr<Value> clone() const override;
     135             : 
     136             : private:
     137    10365126 :     explicit FundamentalValue(bool value) : Value(TypeBoolean), m_boolValue(value) { }
     138     2267818 :     explicit FundamentalValue(int value) : Value(TypeInteger), m_integerValue(value) { }
     139      295968 :     explicit FundamentalValue(double value) : Value(TypeDouble), m_doubleValue(value) { }
     140             : 
     141             :     union {
     142             :         bool m_boolValue;
     143             :         double m_doubleValue;
     144             :         int m_integerValue;
     145             :     };
     146             : };
     147             : 
     148    33746636 : class  StringValue : public Value {
     149             : public:
     150    16873318 :     static std::unique_ptr<StringValue> create(const String& value)
     151             :     {
     152    33746636 :         return std::unique_ptr<StringValue>(new StringValue(value));
     153             :     }
     154             : 
     155             :     static std::unique_ptr<StringValue> create(const char* value)
     156             :     {
     157             :         return std::unique_ptr<StringValue>(new StringValue(value));
     158             :     }
     159             : 
     160             :     bool asString(String* output) const override;
     161             :     void writeJSON(StringBuilder* output) const override;
     162             :     void writeBinary(std::vector<uint8_t>* bytes) const override;
     163             :     std::unique_ptr<Value> clone() const override;
     164             : 
     165             : private:
     166    16873318 :     explicit StringValue(const String& value) : Value(TypeString), m_stringValue(value) { }
     167             :     explicit StringValue(const char* value) : Value(TypeString), m_stringValue(value) { }
     168             : 
     169             :     String m_stringValue;
     170             : };
     171             : 
     172           0 : class  BinaryValue : public Value {
     173             : public:
     174           0 :     static std::unique_ptr<BinaryValue> create(const Binary& value)
     175             :     {
     176           0 :         return std::unique_ptr<BinaryValue>(new BinaryValue(value));
     177             :     }
     178             : 
     179             :     bool asBinary(Binary* output) const override;
     180             :     void writeJSON(StringBuilder* output) const override;
     181             :     void writeBinary(std::vector<uint8_t>* bytes) const override;
     182             :     std::unique_ptr<Value> clone() const override;
     183             : 
     184             : private:
     185           0 :     explicit BinaryValue(const Binary& value) : Value(TypeBinary), m_binaryValue(value) { }
     186             : 
     187             :     Binary m_binaryValue;
     188             : };
     189             : 
     190     1039800 : class  SerializedValue : public Value {
     191             : public:
     192      346600 :     static std::unique_ptr<SerializedValue> fromJSON(const String& value)
     193             :     {
     194      693200 :         return std::unique_ptr<SerializedValue>(new SerializedValue(value));
     195             :     }
     196             : 
     197           0 :     static std::unique_ptr<SerializedValue> fromBinary(std::vector<uint8_t> value)
     198             :     {
     199           0 :         return std::unique_ptr<SerializedValue>(new SerializedValue(std::move(value)));
     200             :     }
     201             : 
     202             :     void writeJSON(StringBuilder* output) const override;
     203             :     void writeBinary(std::vector<uint8_t>* bytes) const override;
     204             :     std::unique_ptr<Value> clone() const override;
     205             : 
     206             : private:
     207     1039800 :     explicit SerializedValue(const String& json) : Value(TypeSerialized), m_serializedJSON(json) { }
     208           0 :     explicit SerializedValue(std::vector<uint8_t> binary) : Value(TypeSerialized), m_serializedBinary(std::move(binary)) { }
     209           0 :     SerializedValue(const String& json, const std::vector<uint8_t>& binary)
     210           0 :         : Value(TypeSerialized), m_serializedJSON(json), m_serializedBinary(binary) { }
     211             :     String m_serializedJSON;
     212             :     std::vector<uint8_t> m_serializedBinary;
     213             : };
     214             : 
     215             : class  DictionaryValue : public Value {
     216             : public:
     217             :     using Entry = std::pair<String, Value*>;
     218     8014001 :     static std::unique_ptr<DictionaryValue> create()
     219             :     {
     220    16028002 :         return std::unique_ptr<DictionaryValue>(new DictionaryValue());
     221             :     }
     222             : 
     223      553010 :     static DictionaryValue* cast(Value* value)
     224             :     {
     225     1369877 :         if (!value || value->type() != TypeObject)
     226             :             return nullptr;
     227             :         return static_cast<DictionaryValue*>(value);
     228             :     }
     229             : 
     230             :     static std::unique_ptr<DictionaryValue> cast(std::unique_ptr<Value> value)
     231             :     {
     232             :         return std::unique_ptr<DictionaryValue>(DictionaryValue::cast(value.release()));
     233             :     }
     234             : 
     235             :     void writeJSON(StringBuilder* output) const override;
     236             :     void writeBinary(std::vector<uint8_t>* bytes) const override;
     237             :     std::unique_ptr<Value> clone() const override;
     238             : 
     239             :     size_t size() const { return m_data.size(); }
     240             : 
     241             :     void setBoolean(const String& name, bool);
     242             :     void setInteger(const String& name, int);
     243             :     void setDouble(const String& name, double);
     244             :     void setString(const String& name, const String&);
     245             :     void setValue(const String& name, std::unique_ptr<Value>);
     246             :     void setObject(const String& name, std::unique_ptr<DictionaryValue>);
     247             :     void setArray(const String& name, std::unique_ptr<ListValue>);
     248             : 
     249             :     bool getBoolean(const String& name, bool* output) const;
     250             :     bool getInteger(const String& name, int* output) const;
     251             :     bool getDouble(const String& name, double* output) const;
     252             :     bool getString(const String& name, String* output) const;
     253             : 
     254             :     DictionaryValue* getObject(const String& name) const;
     255             :     ListValue* getArray(const String& name) const;
     256             :     Value* get(const String& name) const;
     257             :     Entry at(size_t index) const;
     258             : 
     259             :     bool booleanProperty(const String& name, bool defaultValue) const;
     260             :     int integerProperty(const String& name, int defaultValue) const;
     261             :     double doubleProperty(const String& name, double defaultValue) const;
     262             :     void remove(const String& name);
     263             : 
     264             :     ~DictionaryValue() override;
     265             : 
     266             : private:
     267             :     DictionaryValue();
     268             :     template<typename T>
     269    34241178 :     void set(const String& key, std::unique_ptr<T>& value)
     270             :     {
     271             :         DCHECK(value);
     272             :         bool isNew = m_data.find(key) == m_data.end();
     273             :         m_data[key] = std::move(value);
     274    34241178 :         if (isNew)
     275    34229861 :             m_order.push_back(key);
     276    34241178 :     }
     277             : 
     278             :     using Dictionary = std::unordered_map<String, std::unique_ptr<Value>>;
     279             :     Dictionary m_data;
     280             :     std::vector<String> m_order;
     281             : };
     282             : 
     283             : class  ListValue : public Value {
     284             : public:
     285      408699 :     static std::unique_ptr<ListValue> create()
     286             :     {
     287      817398 :         return std::unique_ptr<ListValue>(new ListValue());
     288             :     }
     289             : 
     290         285 :     static ListValue* cast(Value* value)
     291             :     {
     292         570 :         if (!value || value->type() != TypeArray)
     293             :             return nullptr;
     294             :         return static_cast<ListValue*>(value);
     295             :     }
     296             : 
     297             :     static std::unique_ptr<ListValue> cast(std::unique_ptr<Value> value)
     298             :     {
     299             :         return std::unique_ptr<ListValue>(ListValue::cast(value.release()));
     300             :     }
     301             : 
     302             :     ~ListValue() override;
     303             : 
     304             :     void writeJSON(StringBuilder* output) const override;
     305             :     void writeBinary(std::vector<uint8_t>* bytes) const override;
     306             :     std::unique_ptr<Value> clone() const override;
     307             : 
     308             :     void pushValue(std::unique_ptr<Value>);
     309             : 
     310             :     Value* at(size_t index);
     311         630 :     size_t size() const { return m_data.size(); }
     312             : 
     313             : private:
     314             :     ListValue();
     315             :     std::vector<std::unique_ptr<Value>> m_data;
     316             : };
     317             : 
     318             : void escapeLatinStringForJSON(const uint8_t* str, unsigned len, StringBuilder* dst);
     319             : void escapeWideStringForJSON(const uint16_t* str, unsigned len, StringBuilder* dst);
     320             : 
     321             : } // namespace v8_inspector
     322             : } // namespace protocol
     323             : 
     324             : #endif // v8_inspector_protocol_Values_h
     325             : 
     326             : 
     327             : // This file is generated by Object_h.template.
     328             : 
     329             : // Copyright 2016 The Chromium Authors. All rights reserved.
     330             : // Use of this source code is governed by a BSD-style license that can be
     331             : // found in the LICENSE file.
     332             : 
     333             : #ifndef v8_inspector_protocol_Object_h
     334             : #define v8_inspector_protocol_Object_h
     335             : 
     336             : //#include "ErrorSupport.h"
     337             : //#include "Forward.h"
     338             : //#include "Values.h"
     339             : 
     340             : namespace v8_inspector {
     341             : namespace protocol {
     342             : 
     343             : class  Object {
     344             : public:
     345             :     static std::unique_ptr<Object> fromValue(protocol::Value*, ErrorSupport*);
     346             :     explicit Object(std::unique_ptr<protocol::DictionaryValue>);
     347             :     ~Object();
     348             : 
     349             :     std::unique_ptr<protocol::DictionaryValue> toValue() const;
     350             :     std::unique_ptr<Object> clone() const;
     351             : private:
     352             :     std::unique_ptr<protocol::DictionaryValue> m_object;
     353             : };
     354             : 
     355             : } // namespace v8_inspector
     356             : } // namespace protocol
     357             : 
     358             : #endif // !defined(v8_inspector_protocol_Object_h)
     359             : 
     360             : 
     361             : // This file is generated by ValueConversions_h.template.
     362             : 
     363             : // Copyright 2016 The Chromium Authors. All rights reserved.
     364             : // Use of this source code is governed by a BSD-style license that can be
     365             : // found in the LICENSE file.
     366             : 
     367             : #ifndef v8_inspector_protocol_ValueConversions_h
     368             : #define v8_inspector_protocol_ValueConversions_h
     369             : 
     370             : //#include "ErrorSupport.h"
     371             : //#include "Forward.h"
     372             : //#include "Values.h"
     373             : 
     374             : namespace v8_inspector {
     375             : namespace protocol {
     376             : 
     377             : template<typename T>
     378             : struct ValueConversions {
     379           0 :     static std::unique_ptr<T> fromValue(protocol::Value* value, ErrorSupport* errors)
     380             :     {
     381        3213 :         return T::fromValue(value, errors);
     382             :     }
     383             : 
     384       11305 :     static std::unique_ptr<protocol::Value> toValue(T* value)
     385             :     {
     386     8321054 :         return value->toValue();
     387             :     }
     388             : 
     389          30 :     static std::unique_ptr<protocol::Value> toValue(const std::unique_ptr<T>& value)
     390             :     {
     391     6269616 :         return value->toValue();
     392             :     }
     393             : };
     394             : 
     395             : template<>
     396             : struct ValueConversions<bool> {
     397       81974 :     static bool fromValue(protocol::Value* value, ErrorSupport* errors)
     398             :     {
     399       81974 :         bool result = false;
     400       81974 :         bool success = value ? value->asBoolean(&result) : false;
     401       81974 :         if (!success)
     402           0 :             errors->addError("boolean value expected");
     403       81974 :         return result;
     404             :     }
     405             : 
     406             :     static std::unique_ptr<protocol::Value> toValue(bool value)
     407             :     {
     408    20428562 :         return FundamentalValue::create(value);
     409             :     }
     410             : };
     411             : 
     412             : template<>
     413             : struct ValueConversions<int> {
     414        5578 :     static int fromValue(protocol::Value* value, ErrorSupport* errors)
     415             :     {
     416        5578 :         int result = 0;
     417        5578 :         bool success = value ? value->asInteger(&result) : false;
     418        5578 :         if (!success)
     419           0 :             errors->addError("integer value expected");
     420        5578 :         return result;
     421             :     }
     422             : 
     423             :     static std::unique_ptr<protocol::Value> toValue(int value)
     424             :     {
     425     3446194 :         return FundamentalValue::create(value);
     426             :     }
     427             : };
     428             : 
     429             : template<>
     430             : struct ValueConversions<double> {
     431          30 :     static double fromValue(protocol::Value* value, ErrorSupport* errors)
     432             :     {
     433          30 :         double result = 0;
     434          30 :         bool success = value ? value->asDouble(&result) : false;
     435          30 :         if (!success)
     436           0 :             errors->addError("double value expected");
     437          30 :         return result;
     438             :     }
     439             : 
     440             :     static std::unique_ptr<protocol::Value> toValue(double value)
     441             :     {
     442       14020 :         return FundamentalValue::create(value);
     443             :     }
     444             : };
     445             : 
     446             : template<>
     447             : struct ValueConversions<String> {
     448      127133 :     static String fromValue(protocol::Value* value, ErrorSupport* errors)
     449             :     {
     450             :         String result;
     451      127133 :         bool success = value ? value->asString(&result) : false;
     452      127133 :         if (!success)
     453          23 :             errors->addError("string value expected");
     454      127133 :         return result;
     455             :     }
     456             : 
     457             :     static std::unique_ptr<protocol::Value> toValue(const String& value)
     458             :     {
     459    32538966 :         return StringValue::create(value);
     460             :     }
     461             : };
     462             : 
     463             : template<>
     464             : struct ValueConversions<Binary> {
     465             :     static Binary fromValue(protocol::Value* value, ErrorSupport* errors)
     466             :     {
     467             :         String result;
     468             :         bool success = value ? value->asString(&result) : false;
     469             :         if (!success) {
     470             :             errors->addError("string value expected");
     471             :             return Binary();
     472             :         }
     473             :         Binary out = Binary::fromBase64(result, &success);
     474             :         if (!success)
     475             :           errors->addError("base64 decoding error");
     476             :         return out;
     477             :     }
     478             : 
     479             :     static std::unique_ptr<protocol::Value> toValue(const Binary& value)
     480             :     {
     481             :         return StringValue::create(value.toBase64());
     482             :     }
     483             : };
     484             : 
     485             : template<>
     486             : struct ValueConversions<Value> {
     487         271 :     static std::unique_ptr<Value> fromValue(protocol::Value* value, ErrorSupport* errors)
     488             :     {
     489             :         bool success = !!value;
     490         271 :         if (!success) {
     491           0 :             errors->addError("value expected");
     492             :             return nullptr;
     493             :         }
     494         271 :         return value->clone();
     495             :     }
     496             : 
     497             :     static std::unique_ptr<protocol::Value> toValue(Value* value)
     498             :     {
     499      227904 :         return value->clone();
     500             :     }
     501             : 
     502             :     static std::unique_ptr<protocol::Value> toValue(const std::unique_ptr<Value>& value)
     503             :     {
     504             :         return value->clone();
     505             :     }
     506             : };
     507             : 
     508             : template<>
     509             : struct ValueConversions<DictionaryValue> {
     510           0 :     static std::unique_ptr<DictionaryValue> fromValue(protocol::Value* value, ErrorSupport* errors)
     511             :     {
     512           0 :         bool success = value && value->type() == protocol::Value::TypeObject;
     513           0 :         if (!success)
     514           0 :             errors->addError("object expected");
     515           0 :         return DictionaryValue::cast(value->clone());
     516             :     }
     517             : 
     518             :     static std::unique_ptr<protocol::Value> toValue(DictionaryValue* value)
     519             :     {
     520        2029 :         return value->clone();
     521             :     }
     522             : 
     523             :     static std::unique_ptr<protocol::Value> toValue(const std::unique_ptr<DictionaryValue>& value)
     524             :     {
     525             :         return value->clone();
     526             :     }
     527             : };
     528             : 
     529             : template<>
     530             : struct ValueConversions<ListValue> {
     531             :     static std::unique_ptr<ListValue> fromValue(protocol::Value* value, ErrorSupport* errors)
     532             :     {
     533             :         bool success = value && value->type() == protocol::Value::TypeArray;
     534             :         if (!success)
     535             :             errors->addError("list expected");
     536             :         return ListValue::cast(value->clone());
     537             :     }
     538             : 
     539             :     static std::unique_ptr<protocol::Value> toValue(ListValue* value)
     540             :     {
     541             :         return value->clone();
     542             :     }
     543             : 
     544             :     static std::unique_ptr<protocol::Value> toValue(const std::unique_ptr<ListValue>& value)
     545             :     {
     546             :         return value->clone();
     547             :     }
     548             : };
     549             : 
     550             : } // namespace v8_inspector
     551             : } // namespace protocol
     552             : 
     553             : #endif // !defined(v8_inspector_protocol_ValueConversions_h)
     554             : 
     555             : 
     556             : // This file is generated by Maybe_h.template.
     557             : 
     558             : // Copyright 2016 The Chromium Authors. All rights reserved.
     559             : // Use of this source code is governed by a BSD-style license that can be
     560             : // found in the LICENSE file.
     561             : 
     562             : #ifndef v8_inspector_protocol_Maybe_h
     563             : #define v8_inspector_protocol_Maybe_h
     564             : 
     565             : // This macro allows to test for the version of the GNU C++ compiler.
     566             : // Note that this also applies to compilers that masquerade as GCC,
     567             : // for example clang and the Intel C++ compiler for Linux.
     568             : // Use like:
     569             : //  #if IP_GNUC_PREREQ(4, 3, 1)
     570             : //   ...
     571             : //  #endif
     572             : #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
     573             : #define IP_GNUC_PREREQ(major, minor, patchlevel)                      \
     574             :   ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \
     575             :    ((major)*10000 + (minor)*100 + (patchlevel)))
     576             : #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
     577             : #define IP_GNUC_PREREQ(major, minor, patchlevel) \
     578             :   ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >=  \
     579             :    ((major)*10000 + (minor)*100 + (patchlevel)))
     580             : #else
     581             : #define IP_GNUC_PREREQ(major, minor, patchlevel) 0
     582             : #endif
     583             : 
     584             : #if defined(__mips64)
     585             : #define IP_TARGET_ARCH_MIPS64 1
     586             : #elif defined(__MIPSEB__) || defined(__MIPSEL__)
     587             : #define IP_TARGET_ARCH_MIPS 1
     588             : #endif
     589             : 
     590             : // Allowing the use of noexcept by removing the keyword on older compilers that
     591             : // do not support adding noexcept to default members.
     592             : #if ((IP_GNUC_PREREQ(4, 9, 0) && !defined(IP_TARGET_ARCH_MIPS) && \
     593             :       !defined(IP_TARGET_ARCH_MIPS64)) ||                         \
     594             :      (defined(__clang__) && __cplusplus > 201300L))
     595             : #define IP_NOEXCEPT noexcept
     596             : #else
     597             : #define IP_NOEXCEPT
     598             : #endif
     599             : 
     600             : //#include "Forward.h"
     601             : 
     602             : namespace v8_inspector {
     603             : namespace protocol {
     604             : 
     605             : template<typename T>
     606             : class Maybe {
     607             : public:
     608             :     Maybe() : m_value() { }
     609             :     Maybe(std::unique_ptr<T> value) : m_value(std::move(value)) { }
     610             :     Maybe(Maybe&& other) IP_NOEXCEPT : m_value(std::move(other.m_value)) {}
     611             :     void operator=(std::unique_ptr<T> value) { m_value = std::move(value); }
     612             :     T* fromJust() const { DCHECK(m_value); return m_value.get(); }
     613             :     T* fromMaybe(T* defaultValue) const { return m_value ? m_value.get() : defaultValue; }
     614             :     bool isJust() const { return !!m_value; }
     615             :     std::unique_ptr<T> takeJust() { DCHECK(m_value); return std::move(m_value); }
     616             : private:
     617             :     std::unique_ptr<T> m_value;
     618             : };
     619             : 
     620             : template<typename T>
     621             : class MaybeBase {
     622             : public:
     623    24405275 :     MaybeBase() : m_isJust(false) { }
     624      297514 :     MaybeBase(T value) : m_isJust(true), m_value(value) { }
     625             :     MaybeBase(MaybeBase&& other) IP_NOEXCEPT
     626             :         : m_isJust(other.m_isJust),
     627      206383 :           m_value(std::move(other.m_value)) {}
     628    14665562 :     void operator=(T value) { m_value = value; m_isJust = true; }
     629             :     T fromJust() const { DCHECK(m_isJust); return m_value; }
     630      450996 :     T fromMaybe(const T& defaultValue) const { return m_isJust ? m_value : defaultValue; }
     631             :     bool isJust() const { return m_isJust; }
     632             :     T takeJust() { DCHECK(m_isJust); return m_value; }
     633             : 
     634             : protected:
     635             :     bool m_isJust;
     636             :     T m_value;
     637             : };
     638             : 
     639             : template<>
     640             : class Maybe<bool> : public MaybeBase<bool> {
     641             : public:
     642     7696517 :     Maybe() { m_value = false; }
     643             :     Maybe(bool value) : MaybeBase(value) { }
     644             :     Maybe(Maybe&& other) IP_NOEXCEPT : MaybeBase(std::move(other)) {}
     645             :     using MaybeBase::operator=;
     646             : };
     647             : 
     648             : template<>
     649             : class Maybe<int> : public MaybeBase<int> {
     650             : public:
     651      673426 :     Maybe() { m_value = 0; }
     652             :     Maybe(int value) : MaybeBase(value) { }
     653             :     Maybe(Maybe&& other) IP_NOEXCEPT : MaybeBase(std::move(other)) {}
     654             :     using MaybeBase::operator=;
     655             : };
     656             : 
     657             : template<>
     658             : class Maybe<double> : public MaybeBase<double> {
     659             : public:
     660             :     Maybe() { m_value = 0; }
     661             :     Maybe(double value) : MaybeBase(value) { }
     662             :     Maybe(Maybe&& other) IP_NOEXCEPT : MaybeBase(std::move(other)) {}
     663             :     using MaybeBase::operator=;
     664             : };
     665             : 
     666             : template<>
     667             : class Maybe<String> : public MaybeBase<String> {
     668             : public:
     669             :     Maybe() { }
     670      121204 :     Maybe(const String& value) : MaybeBase(value) { }
     671             :     Maybe(Maybe&& other) IP_NOEXCEPT : MaybeBase(std::move(other)) {}
     672             :     using MaybeBase::operator=;
     673             : };
     674             : 
     675             : template<>
     676             : class Maybe<Binary> : public MaybeBase<Binary> {
     677             : public:
     678             :     Maybe() { }
     679             :     Maybe(Binary value) : MaybeBase(value) { }
     680             :     Maybe(Maybe&& other) IP_NOEXCEPT : MaybeBase(std::move(other)) {}
     681             :     using MaybeBase::operator=;
     682             : };
     683             : 
     684             : } // namespace v8_inspector
     685             : } // namespace protocol
     686             : 
     687             : #undef IP_GNUC_PREREQ
     688             : #undef IP_TARGET_ARCH_MIPS64
     689             : #undef IP_TARGET_ARCH_MIPS
     690             : #undef IP_NOEXCEPT
     691             : 
     692             : #endif // !defined(v8_inspector_protocol_Maybe_h)
     693             : 
     694             : 
     695             : // This file is generated by Array_h.template.
     696             : 
     697             : // Copyright 2016 The Chromium Authors. All rights reserved.
     698             : // Use of this source code is governed by a BSD-style license that can be
     699             : // found in the LICENSE file.
     700             : 
     701             : #ifndef v8_inspector_protocol_Array_h
     702             : #define v8_inspector_protocol_Array_h
     703             : 
     704             : //#include "ErrorSupport.h"
     705             : //#include "Forward.h"
     706             : //#include "ValueConversions.h"
     707             : //#include "Values.h"
     708             : 
     709             : namespace v8_inspector {
     710             : namespace protocol {
     711             : 
     712             : template<typename T>
     713      420126 : class Array {
     714             : public:
     715             :     static std::unique_ptr<Array<T>> create()
     716             :     {
     717      419946 :         return std::unique_ptr<Array<T>>(new Array<T>());
     718             :     }
     719             : 
     720         180 :     static std::unique_ptr<Array<T>> fromValue(protocol::Value* value, ErrorSupport* errors)
     721             :     {
     722             :         protocol::ListValue* array = ListValue::cast(value);
     723         180 :         if (!array) {
     724           0 :             errors->addError("array expected");
     725             :             return nullptr;
     726             :         }
     727         180 :         std::unique_ptr<Array<T>> result(new Array<T>());
     728         180 :         errors->push();
     729         830 :         for (size_t i = 0; i < array->size(); ++i) {
     730         470 :             errors->setName(StringUtil::fromInteger(i));
     731         235 :             std::unique_ptr<T> item = ValueConversions<T>::fromValue(array->at(i), errors);
     732         235 :             result->m_vector.push_back(std::move(item));
     733             :         }
     734         180 :         errors->pop();
     735         180 :         if (errors->hasErrors())
     736             :             return nullptr;
     737             :         return result;
     738             :     }
     739             : 
     740             :     void addItem(std::unique_ptr<T> value)
     741             :     {
     742     3134846 :         m_vector.push_back(std::move(value));
     743             :     }
     744             : 
     745             :     size_t length()
     746             :     {
     747       68778 :         return m_vector.size();
     748             :     }
     749             : 
     750             :     T* get(size_t index)
     751             :     {
     752         140 :         return m_vector[index].get();
     753             :     }
     754             : 
     755      351910 :     std::unique_ptr<protocol::ListValue> toValue()
     756             :     {
     757      351910 :         std::unique_ptr<protocol::ListValue> result = ListValue::create();
     758     3838628 :         for (auto& item : m_vector)
     759     6269646 :             result->pushValue(ValueConversions<T>::toValue(item));
     760      351910 :         return result;
     761             :     }
     762             : 
     763             : private:
     764             :     std::vector<std::unique_ptr<T>> m_vector;
     765             : };
     766             : 
     767             : template<typename T>
     768       55556 : class ArrayBase {
     769             : public:
     770             :     static std::unique_ptr<Array<T>> create()
     771             :     {
     772       55594 :         return std::unique_ptr<Array<T>>(new Array<T>());
     773             :     }
     774             : 
     775         105 :     static std::unique_ptr<Array<T>> fromValue(protocol::Value* value, ErrorSupport* errors)
     776             :     {
     777             :         protocol::ListValue* array = ListValue::cast(value);
     778         105 :         if (!array) {
     779           0 :             errors->addError("array expected");
     780             :             return nullptr;
     781             :         }
     782         105 :         errors->push();
     783         105 :         std::unique_ptr<Array<T>> result(new Array<T>());
     784         430 :         for (size_t i = 0; i < array->size(); ++i) {
     785         220 :             errors->setName(StringUtil::fromInteger(i));
     786         110 :             T item = ValueConversions<T>::fromValue(array->at(i), errors);
     787         110 :             result->m_vector.push_back(item);
     788             :         }
     789         105 :         errors->pop();
     790         105 :         if (errors->hasErrors())
     791             :             return nullptr;
     792             :         return result;
     793             :     }
     794             : 
     795             :     void addItem(const T& value)
     796             :     {
     797        2703 :         m_vector.push_back(value);
     798             :     }
     799             : 
     800             :     size_t length()
     801             :     {
     802         215 :         return m_vector.size();
     803             :     }
     804             : 
     805             :     T get(size_t index)
     806             :     {
     807             :         return m_vector[index];
     808             :     }
     809             : 
     810       55594 :     std::unique_ptr<protocol::ListValue> toValue()
     811             :     {
     812       55594 :         std::unique_ptr<protocol::ListValue> result = ListValue::create();
     813      113891 :         for (auto& item : m_vector)
     814        5555 :             result->pushValue(ValueConversions<T>::toValue(item));
     815       55594 :         return result;
     816             :     }
     817             : 
     818             : private:
     819             :     std::vector<T> m_vector;
     820             : };
     821             : 
     822             : template<> class Array<String> : public ArrayBase<String> {};
     823             : template<> class Array<int> : public ArrayBase<int> {};
     824             : template<> class Array<double> : public ArrayBase<double> {};
     825             : template<> class Array<bool> : public ArrayBase<bool> {};
     826             : 
     827             : } // namespace v8_inspector
     828             : } // namespace protocol
     829             : 
     830             : #endif // !defined(v8_inspector_protocol_Array_h)
     831             : 
     832             : 
     833             : // This file is generated by DispatcherBase_h.template.
     834             : 
     835             : // Copyright 2016 The Chromium Authors. All rights reserved.
     836             : // Use of this source code is governed by a BSD-style license that can be
     837             : // found in the LICENSE file.
     838             : 
     839             : #ifndef v8_inspector_protocol_DispatcherBase_h
     840             : #define v8_inspector_protocol_DispatcherBase_h
     841             : 
     842             : //#include "Forward.h"
     843             : //#include "ErrorSupport.h"
     844             : //#include "Values.h"
     845             : 
     846             : namespace v8_inspector {
     847             : namespace protocol {
     848             : 
     849             : class WeakPtr;
     850             : 
     851    12135840 : class  DispatchResponse {
     852             : public:
     853             :     enum Status {
     854             :         kSuccess = 0,
     855             :         kError = 1,
     856             :         kFallThrough = 2,
     857             :     };
     858             : 
     859             :     enum ErrorCode {
     860             :         kParseError = -32700,
     861             :         kInvalidRequest = -32600,
     862             :         kMethodNotFound = -32601,
     863             :         kInvalidParams = -32602,
     864             :         kInternalError = -32603,
     865             :         kServerError = -32000,
     866             :     };
     867             : 
     868             :     Status status() const { return m_status; }
     869             :     const String& errorMessage() const { return m_errorMessage; }
     870             :     ErrorCode errorCode() const { return m_errorCode; }
     871             :     bool isSuccess() const { return m_status == kSuccess; }
     872             : 
     873             :     static DispatchResponse OK();
     874             :     static DispatchResponse Error(const String&);
     875             :     static DispatchResponse InternalError();
     876             :     static DispatchResponse InvalidParams(const String&);
     877             :     static DispatchResponse FallThrough();
     878             : 
     879             : private:
     880             :     Status m_status;
     881             :     String m_errorMessage;
     882             :     ErrorCode m_errorCode;
     883             : };
     884             : 
     885             : class  DispatcherBase {
     886             :     PROTOCOL_DISALLOW_COPY(DispatcherBase);
     887             : public:
     888             :     static const char kInvalidParamsString[];
     889             :     class  WeakPtr {
     890             :     public:
     891             :         explicit WeakPtr(DispatcherBase*);
     892             :         ~WeakPtr();
     893      280118 :         DispatcherBase* get() { return m_dispatcher; }
     894          10 :         void dispose() { m_dispatcher = nullptr; }
     895             : 
     896             :     private:
     897             :         DispatcherBase* m_dispatcher;
     898             :     };
     899             : 
     900       18832 :     class  Callback {
     901             :     public:
     902             :         Callback(std::unique_ptr<WeakPtr> backendImpl, int callId, const String& method, const ProtocolMessage& message);
     903             :         virtual ~Callback();
     904             :         void dispose();
     905             : 
     906             :     protected:
     907             :         void sendIfActive(std::unique_ptr<protocol::DictionaryValue> partialMessage, const DispatchResponse& response);
     908             :         void fallThroughIfActive();
     909             : 
     910             :     private:
     911             :         std::unique_ptr<WeakPtr> m_backendImpl;
     912             :         int m_callId;
     913             :         String m_method;
     914             :         ProtocolMessage m_message;
     915             :     };
     916             : 
     917             :     explicit DispatcherBase(FrontendChannel*);
     918             :     virtual ~DispatcherBase();
     919             : 
     920             :     virtual bool canDispatch(const String& method) = 0;
     921             :     virtual void dispatch(int callId, const String& method, const ProtocolMessage& rawMessage, std::unique_ptr<protocol::DictionaryValue> messageObject) = 0;
     922             :     FrontendChannel* channel() { return m_frontendChannel; }
     923             : 
     924             :     void sendResponse(int callId, const DispatchResponse&, std::unique_ptr<protocol::DictionaryValue> result);
     925             :     void sendResponse(int callId, const DispatchResponse&);
     926             : 
     927             :     void reportProtocolError(int callId, DispatchResponse::ErrorCode, const String& errorMessage, ErrorSupport* errors);
     928             :     void clearFrontend();
     929             : 
     930             :     std::unique_ptr<WeakPtr> weakPtr();
     931             : 
     932             : private:
     933             :     FrontendChannel* m_frontendChannel;
     934             :     std::unordered_set<WeakPtr*> m_weakPtrs;
     935             : };
     936             : 
     937        7664 : class  UberDispatcher {
     938             :     PROTOCOL_DISALLOW_COPY(UberDispatcher);
     939             : public:
     940             :     explicit UberDispatcher(FrontendChannel*);
     941             :     void registerBackend(const String& name, std::unique_ptr<protocol::DispatcherBase>);
     942             :     void setupRedirects(const std::unordered_map<String, String>&);
     943             :     bool parseCommand(Value* message, int* callId, String* method);
     944             :     bool canDispatch(const String& method);
     945             :     void dispatch(int callId, const String& method, std::unique_ptr<Value> message, const ProtocolMessage& rawMessage);
     946             :     FrontendChannel* channel() { return m_frontendChannel; }
     947             :     virtual ~UberDispatcher();
     948             : 
     949             : private:
     950             :     protocol::DispatcherBase* findDispatcher(const String& method);
     951             :     FrontendChannel* m_frontendChannel;
     952             :     std::unordered_map<String, String> m_redirects;
     953             :     std::unordered_map<String, std::unique_ptr<protocol::DispatcherBase>> m_dispatchers;
     954             : };
     955             : 
     956             : class InternalResponse : public Serializable {
     957             :     PROTOCOL_DISALLOW_COPY(InternalResponse);
     958             : public:
     959             :     static std::unique_ptr<InternalResponse> createResponse(int callId, std::unique_ptr<Serializable> params);
     960             :     static std::unique_ptr<InternalResponse> createNotification(const String& notification, std::unique_ptr<Serializable> params = nullptr);
     961             : 
     962             :     String serializeToJSON() override;
     963             :     std::vector<uint8_t> serializeToBinary() override;
     964             : 
     965     1039800 :     ~InternalResponse() override {}
     966             : 
     967             : private:
     968             :     InternalResponse(int callId, const String& notification, std::unique_ptr<Serializable> params);
     969             : 
     970             :     int m_callId;
     971             :     String m_notification;
     972             :     std::unique_ptr<Serializable> m_params;
     973             : };
     974             : 
     975             : class InternalRawNotification : public Serializable {
     976             : public:
     977           0 :     static std::unique_ptr<InternalRawNotification> fromJSON(String notification)
     978             :     {
     979           0 :         return std::unique_ptr<InternalRawNotification>(new InternalRawNotification(std::move(notification)));
     980             :     }
     981             : 
     982           0 :     static std::unique_ptr<InternalRawNotification> fromBinary(std::vector<uint8_t> notification)
     983             :     {
     984           0 :         return std::unique_ptr<InternalRawNotification>(new InternalRawNotification(std::move(notification)));
     985             :     }
     986             : 
     987           0 :     ~InternalRawNotification() override {}
     988             : 
     989           0 :     String serializeToJSON() override
     990             :     {
     991           0 :         return std::move(m_jsonNotification);
     992             :     }
     993             : 
     994           0 :     std::vector<uint8_t> serializeToBinary() override
     995             :     {
     996           0 :         return std::move(m_binaryNotification);
     997             :     }
     998             : 
     999             : private:
    1000             :   explicit InternalRawNotification(String notification)
    1001           0 :     : m_jsonNotification(std::move(notification)) { }
    1002             :   explicit InternalRawNotification(std::vector<uint8_t> notification)
    1003           0 :     : m_binaryNotification(std::move(notification)) { }
    1004             : 
    1005             :   String m_jsonNotification;
    1006             :   std::vector<uint8_t> m_binaryNotification;
    1007             : };
    1008             : 
    1009             : } // namespace v8_inspector
    1010             : } // namespace protocol
    1011             : 
    1012             : #endif // !defined(v8_inspector_protocol_DispatcherBase_h)
    1013             : 
    1014             : 
    1015             : // This file is generated by Parser_h.template.
    1016             : 
    1017             : // Copyright 2016 The Chromium Authors. All rights reserved.
    1018             : // Use of this source code is governed by a BSD-style license that can be
    1019             : // found in the LICENSE file.
    1020             : 
    1021             : #ifndef v8_inspector_protocol_Parser_h
    1022             : #define v8_inspector_protocol_Parser_h
    1023             : 
    1024             : //#include "Forward.h"
    1025             : //#include "Values.h"
    1026             : 
    1027             : namespace v8_inspector {
    1028             : namespace protocol {
    1029             : 
    1030             :  std::unique_ptr<Value> parseJSONCharacters(const uint8_t*, unsigned);
    1031             :  std::unique_ptr<Value> parseJSONCharacters(const uint16_t*, unsigned);
    1032             : 
    1033             : } // namespace v8_inspector
    1034             : } // namespace protocol
    1035             : 
    1036             : #endif // !defined(v8_inspector_protocol_Parser_h)
    1037             : 
    1038             : 
    1039             : // Generated by lib/CBOR_h.template.
    1040             : 
    1041             : // Copyright 2019 The Chromium Authors. All rights reserved.
    1042             : // Use of this source code is governed by a BSD-style license that can be
    1043             : // found in the LICENSE file.
    1044             : 
    1045             : #ifndef v8_inspector_protocol_CBOR_h
    1046             : #define v8_inspector_protocol_CBOR_h
    1047             : 
    1048             : #include <cstddef>
    1049             : #include <cstdint>
    1050             : #include <memory>
    1051             : #include <vector>
    1052             : 
    1053             : namespace v8_inspector {
    1054             : namespace protocol {
    1055             : 
    1056             : // ===== encoding/status.h =====
    1057             : 
    1058             : // Error codes.
    1059             : enum class Error {
    1060             :   OK = 0,
    1061             :   // JSON parsing errors - json_parser.{h,cc}.
    1062             :   JSON_PARSER_UNPROCESSED_INPUT_REMAINS = 0x01,
    1063             :   JSON_PARSER_STACK_LIMIT_EXCEEDED = 0x02,
    1064             :   JSON_PARSER_NO_INPUT = 0x03,
    1065             :   JSON_PARSER_INVALID_TOKEN = 0x04,
    1066             :   JSON_PARSER_INVALID_NUMBER = 0x05,
    1067             :   JSON_PARSER_INVALID_STRING = 0x06,
    1068             :   JSON_PARSER_UNEXPECTED_ARRAY_END = 0x07,
    1069             :   JSON_PARSER_COMMA_OR_ARRAY_END_EXPECTED = 0x08,
    1070             :   JSON_PARSER_STRING_LITERAL_EXPECTED = 0x09,
    1071             :   JSON_PARSER_COLON_EXPECTED = 0x0a,
    1072             :   JSON_PARSER_UNEXPECTED_OBJECT_END = 0x0b,
    1073             :   JSON_PARSER_COMMA_OR_OBJECT_END_EXPECTED = 0x0c,
    1074             :   JSON_PARSER_VALUE_EXPECTED = 0x0d,
    1075             : 
    1076             :   CBOR_INVALID_INT32 = 0x0e,
    1077             :   CBOR_INVALID_DOUBLE = 0x0f,
    1078             :   CBOR_INVALID_ENVELOPE = 0x10,
    1079             :   CBOR_INVALID_STRING8 = 0x11,
    1080             :   CBOR_INVALID_STRING16 = 0x12,
    1081             :   CBOR_INVALID_BINARY = 0x13,
    1082             :   CBOR_UNSUPPORTED_VALUE = 0x14,
    1083             :   CBOR_NO_INPUT = 0x15,
    1084             :   CBOR_INVALID_START_BYTE = 0x16,
    1085             :   CBOR_UNEXPECTED_EOF_EXPECTED_VALUE = 0x17,
    1086             :   CBOR_UNEXPECTED_EOF_IN_ARRAY = 0x18,
    1087             :   CBOR_UNEXPECTED_EOF_IN_MAP = 0x19,
    1088             :   CBOR_INVALID_MAP_KEY = 0x1a,
    1089             :   CBOR_STACK_LIMIT_EXCEEDED = 0x1b,
    1090             :   CBOR_STRING8_MUST_BE_7BIT = 0x1c,
    1091             :   CBOR_TRAILING_JUNK = 0x1d,
    1092             :   CBOR_MAP_START_EXPECTED = 0x1e,
    1093             : };
    1094             : 
    1095             : // A status value with position that can be copied. The default status
    1096             : // is OK. Usually, error status values should come with a valid position.
    1097             : struct Status {
    1098             :   static constexpr std::ptrdiff_t npos() { return -1; }
    1099             : 
    1100             :   bool ok() const { return error == Error::OK; }
    1101             : 
    1102             :   Error error = Error::OK;
    1103             :   std::ptrdiff_t pos = npos();
    1104           0 :   Status(Error error, std::ptrdiff_t pos) : error(error), pos(pos) {}
    1105             :   Status() = default;
    1106             : };
    1107             : 
    1108             : // ===== encoding/span.h =====
    1109             : 
    1110             : // This template is similar to std::span, which will be included in C++20.  Like
    1111             : // std::span it uses ptrdiff_t, which is signed (and thus a bit annoying
    1112             : // sometimes when comparing with size_t), but other than this it's much simpler.
    1113             : template <typename T>
    1114             : class span {
    1115             :  public:
    1116             :   using index_type = std::ptrdiff_t;
    1117             : 
    1118             :   span() : data_(nullptr), size_(0) {}
    1119           0 :   span(const T* data, index_type size) : data_(data), size_(size) {}
    1120             : 
    1121             :   const T* data() const { return data_; }
    1122             : 
    1123             :   const T* begin() const { return data_; }
    1124           0 :   const T* end() const { return data_ + size_; }
    1125             : 
    1126           0 :   const T& operator[](index_type idx) const { return data_[idx]; }
    1127             : 
    1128             :   span<T> subspan(index_type offset, index_type count) const {
    1129           0 :     return span(data_ + offset, count);
    1130             :   }
    1131             : 
    1132             :   span<T> subspan(index_type offset) const {
    1133           0 :     return span(data_ + offset, size_ - offset);
    1134             :   }
    1135             : 
    1136             :   bool empty() const { return size_ == 0; }
    1137             : 
    1138             :   index_type size() const { return size_; }
    1139           0 :   index_type size_bytes() const { return size_ * sizeof(T); }
    1140             : 
    1141             :  private:
    1142             :   const T* data_;
    1143             :   index_type size_;
    1144             : };
    1145             : 
    1146             : // ===== encoding/json_parser_handler.h =====
    1147             : 
    1148             : // Handler interface for JSON parser events. See also json_parser.h.
    1149           0 : class JSONParserHandler {
    1150             :  public:
    1151           0 :   virtual ~JSONParserHandler() = default;
    1152             :   virtual void HandleObjectBegin() = 0;
    1153             :   virtual void HandleObjectEnd() = 0;
    1154             :   virtual void HandleArrayBegin() = 0;
    1155             :   virtual void HandleArrayEnd() = 0;
    1156             :   // TODO(johannes): Support utf8 (requires utf16->utf8 conversion
    1157             :   // internally, including handling mismatched surrogate pairs).
    1158             :   virtual void HandleString16(std::vector<uint16_t> chars) = 0;
    1159             :   virtual void HandleBinary(std::vector<uint8_t> bytes) = 0;
    1160             :   virtual void HandleDouble(double value) = 0;
    1161             :   virtual void HandleInt32(int32_t value) = 0;
    1162             :   virtual void HandleBool(bool value) = 0;
    1163             :   virtual void HandleNull() = 0;
    1164             : 
    1165             :   // The parser may send one error even after other events have already
    1166             :   // been received. Client code is reponsible to then discard the
    1167             :   // already processed events.
    1168             :   // |error| must be an eror, as in, |error.is_ok()| can't be true.
    1169             :   virtual void HandleError(Status error) = 0;
    1170             : };
    1171             : 
    1172             : // ===== encoding/cbor_internals.h =====
    1173             : 
    1174             : namespace cbor {
    1175             : enum class MajorType;
    1176             : }
    1177             : 
    1178             : namespace cbor_internals {
    1179             : 
    1180             : // Reads the start of a token with definitive size from |bytes|.
    1181             : // |type| is the major type as specified in RFC 7049 Section 2.1.
    1182             : // |value| is the payload (e.g. for MajorType::UNSIGNED) or is the size
    1183             : // (e.g. for BYTE_STRING).
    1184             : // If successful, returns the number of bytes read. Otherwise returns -1.
    1185             : int8_t ReadTokenStart(span<uint8_t> bytes, cbor::MajorType* type,
    1186             :                       uint64_t* value);
    1187             : 
    1188             : // Writes the start of a token with |type|. The |value| may indicate the size,
    1189             : // or it may be the payload if the value is an unsigned integer.
    1190             : void WriteTokenStart(cbor::MajorType type, uint64_t value,
    1191             :                      std::vector<uint8_t>* encoded);
    1192             : }  // namespace cbor_internals
    1193             : 
    1194             : // ===== encoding/cbor.h =====
    1195             : 
    1196             : 
    1197             : namespace cbor {
    1198             : 
    1199             : // The major types from RFC 7049 Section 2.1.
    1200             : enum class MajorType {
    1201             :   UNSIGNED = 0,
    1202             :   NEGATIVE = 1,
    1203             :   BYTE_STRING = 2,
    1204             :   STRING = 3,
    1205             :   ARRAY = 4,
    1206             :   MAP = 5,
    1207             :   TAG = 6,
    1208             :   SIMPLE_VALUE = 7
    1209             : };
    1210             : 
    1211             : // Indicates the number of bits the "initial byte" needs to be shifted to the
    1212             : // right after applying |kMajorTypeMask| to produce the major type in the
    1213             : // lowermost bits.
    1214             : static constexpr uint8_t kMajorTypeBitShift = 5u;
    1215             : // Mask selecting the low-order 5 bits of the "initial byte", which is where
    1216             : // the additional information is encoded.
    1217             : static constexpr uint8_t kAdditionalInformationMask = 0x1f;
    1218             : // Mask selecting the high-order 3 bits of the "initial byte", which indicates
    1219             : // the major type of the encoded value.
    1220             : static constexpr uint8_t kMajorTypeMask = 0xe0;
    1221             : // Indicates the integer is in the following byte.
    1222             : static constexpr uint8_t kAdditionalInformation1Byte = 24u;
    1223             : // Indicates the integer is in the next 2 bytes.
    1224             : static constexpr uint8_t kAdditionalInformation2Bytes = 25u;
    1225             : // Indicates the integer is in the next 4 bytes.
    1226             : static constexpr uint8_t kAdditionalInformation4Bytes = 26u;
    1227             : // Indicates the integer is in the next 8 bytes.
    1228             : static constexpr uint8_t kAdditionalInformation8Bytes = 27u;
    1229             : 
    1230             : // Encodes the initial byte, consisting of the |type| in the first 3 bits
    1231             : // followed by 5 bits of |additional_info|.
    1232             : constexpr uint8_t EncodeInitialByte(MajorType type, uint8_t additional_info) {
    1233           0 :   return (static_cast<uint8_t>(type) << kMajorTypeBitShift) |
    1234           0 :          (additional_info & kAdditionalInformationMask);
    1235             : }
    1236             : 
    1237             : // TAG 24 indicates that what follows is a byte string which is
    1238             : // encoded in CBOR format. We use this as a wrapper for
    1239             : // maps and arrays, allowing us to skip them, because the
    1240             : // byte string carries its size (byte length).
    1241             : // https://tools.ietf.org/html/rfc7049#section-2.4.4.1
    1242             : static constexpr uint8_t kInitialByteForEnvelope =
    1243             :     EncodeInitialByte(MajorType::TAG, 24);
    1244             : // The initial byte for a byte string with at most 2^32 bytes
    1245             : // of payload. This is used for envelope encoding, even if
    1246             : // the byte string is shorter.
    1247             : static constexpr uint8_t kInitialByteFor32BitLengthByteString =
    1248             :     EncodeInitialByte(MajorType::BYTE_STRING, 26);
    1249             : 
    1250             : // See RFC 7049 Section 2.2.1, indefinite length arrays / maps have additional
    1251             : // info = 31.
    1252             : static constexpr uint8_t kInitialByteIndefiniteLengthArray =
    1253             :     EncodeInitialByte(MajorType::ARRAY, 31);
    1254             : static constexpr uint8_t kInitialByteIndefiniteLengthMap =
    1255             :     EncodeInitialByte(MajorType::MAP, 31);
    1256             : // See RFC 7049 Section 2.3, Table 1; this is used for finishing indefinite
    1257             : // length maps / arrays.
    1258             : static constexpr uint8_t kStopByte =
    1259             :     EncodeInitialByte(MajorType::SIMPLE_VALUE, 31);
    1260             : 
    1261             : }  // namespace cbor
    1262             : 
    1263             : // The binary encoding for the inspector protocol follows the CBOR specification
    1264             : // (RFC 7049). Additional constraints:
    1265             : // - Only indefinite length maps and arrays are supported.
    1266             : // - Maps and arrays are wrapped with an envelope, that is, a
    1267             : //   CBOR tag with value 24 followed by a byte string specifying
    1268             : //   the byte length of the enclosed map / array. The byte string
    1269             : //   must use a 32 bit wide length.
    1270             : // - At the top level, a message must be an indefinite length map
    1271             : //   wrapped by an envelope.
    1272             : // - Maximal size for messages is 2^32 (4 GB).
    1273             : // - For scalars, we support only the int32_t range, encoded as
    1274             : //   UNSIGNED/NEGATIVE (major types 0 / 1).
    1275             : // - UTF16 strings, including with unbalanced surrogate pairs, are encoded
    1276             : //   as CBOR BYTE_STRING (major type 2). For such strings, the number of
    1277             : //   bytes encoded must be even.
    1278             : // - UTF8 strings (major type 3) may only have ASCII characters
    1279             : //   (7 bit US-ASCII).
    1280             : // - Arbitrary byte arrays, in the inspector protocol called 'binary',
    1281             : //   are encoded as BYTE_STRING (major type 2), prefixed with a byte
    1282             : //   indicating base64 when rendered as JSON.
    1283             : 
    1284             : // Encodes |value| as |UNSIGNED| (major type 0) iff >= 0, or |NEGATIVE|
    1285             : // (major type 1) iff < 0.
    1286             : void EncodeInt32(int32_t value, std::vector<uint8_t>* out);
    1287             : 
    1288             : // Encodes a UTF16 string as a BYTE_STRING (major type 2). Each utf16
    1289             : // character in |in| is emitted with most significant byte first,
    1290             : // appending to |out|.
    1291             : void EncodeString16(span<uint16_t> in, std::vector<uint8_t>* out);
    1292             : 
    1293             : // Encodes a UTF8 string |in| as STRING (major type 3).
    1294             : void EncodeString8(span<uint8_t> in, std::vector<uint8_t>* out);
    1295             : 
    1296             : // Encodes arbitrary binary data in |in| as a BYTE_STRING (major type 2) with
    1297             : // definitive length, prefixed with tag 22 indicating expected conversion to
    1298             : // base64 (see RFC 7049, Table 3 and Section 2.4.4.2).
    1299             : void EncodeBinary(span<uint8_t> in, std::vector<uint8_t>* out);
    1300             : 
    1301             : // Encodes / decodes a double as Major type 7 (SIMPLE_VALUE),
    1302             : // with additional info = 27, followed by 8 bytes in big endian.
    1303             : void EncodeDouble(double value, std::vector<uint8_t>* out);
    1304             : 
    1305             : // Some constants for CBOR tokens that only take a single byte on the wire.
    1306             : uint8_t EncodeTrue();
    1307             : uint8_t EncodeFalse();
    1308             : uint8_t EncodeNull();
    1309             : uint8_t EncodeIndefiniteLengthArrayStart();
    1310             : uint8_t EncodeIndefiniteLengthMapStart();
    1311             : uint8_t EncodeStop();
    1312             : 
    1313             : // An envelope indicates the byte length of a wrapped item.
    1314             : // We use this for maps and array, which allows the decoder
    1315             : // to skip such (nested) values whole sale.
    1316             : // It's implemented as a CBOR tag (major type 6) with additional
    1317             : // info = 24, followed by a byte string with a 32 bit length value;
    1318             : // so the maximal structure that we can wrap is 2^32 bits long.
    1319             : // See also: https://tools.ietf.org/html/rfc7049#section-2.4.4.1
    1320             : class EnvelopeEncoder {
    1321             :  public:
    1322             :   // Emits the envelope start bytes and records the position for the
    1323             :   // byte size in |byte_size_pos_|. Also emits empty bytes for the
    1324             :   // byte sisze so that encoding can continue.
    1325             :   void EncodeStart(std::vector<uint8_t>* out);
    1326             :   // This records the current size in |out| at position byte_size_pos_.
    1327             :   // Returns true iff successful.
    1328             :   bool EncodeStop(std::vector<uint8_t>* out);
    1329             : 
    1330             :  private:
    1331             :   std::size_t byte_size_pos_ = 0;
    1332             : };
    1333             : 
    1334             : // This can be used to convert from JSON to CBOR, by passing the
    1335             : // return value to the routines in json_parser.h.  The handler will encode into
    1336             : // |out|, and iff an error occurs it will set |status| to an error and clear
    1337             : // |out|. Otherwise, |status.ok()| will be |true|.
    1338             : std::unique_ptr<JSONParserHandler> NewJSONToCBOREncoder(
    1339             :     std::vector<uint8_t>* out, Status* status);
    1340             : 
    1341             : // Parses a CBOR encoded message from |bytes|, sending JSON events to
    1342             : // |json_out|. If an error occurs, sends |out->HandleError|, and parsing stops.
    1343             : // The client is responsible for discarding the already received information in
    1344             : // that case.
    1345             : void ParseCBOR(span<uint8_t> bytes, JSONParserHandler* json_out);
    1346             : 
    1347             : // Tags for the tokens within a CBOR message that CBORStream understands.
    1348             : // Note that this is not the same terminology as the CBOR spec (RFC 7049),
    1349             : // but rather, our adaptation. For instance, we lump unsigned and signed
    1350             : // major type into INT32 here (and disallow values outside the int32_t range).
    1351             : enum class CBORTokenTag {
    1352             :   // Encountered an error in the structure of the message. Consult
    1353             :   // status() for details.
    1354             :   ERROR_VALUE,
    1355             :   // Booleans and NULL.
    1356             :   TRUE_VALUE,
    1357             :   FALSE_VALUE,
    1358             :   NULL_VALUE,
    1359             :   // An int32_t (signed 32 bit integer).
    1360             :   INT32,
    1361             :   // A double (64 bit floating point).
    1362             :   DOUBLE,
    1363             :   // A UTF8 string.
    1364             :   STRING8,
    1365             :   // A UTF16 string.
    1366             :   STRING16,
    1367             :   // A binary string.
    1368             :   BINARY,
    1369             :   // Starts an indefinite length map; after the map start we expect
    1370             :   // alternating keys and values, followed by STOP.
    1371             :   MAP_START,
    1372             :   // Starts an indefinite length array; after the array start we
    1373             :   // expect values, followed by STOP.
    1374             :   ARRAY_START,
    1375             :   // Ends a map or an array.
    1376             :   STOP,
    1377             :   // An envelope indicator, wrapping a map or array.
    1378             :   // Internally this carries the byte length of the wrapped
    1379             :   // map or array. While CBORTokenizer::Next() will read / skip the entire
    1380             :   // envelope, CBORTokenizer::EnterEnvelope() reads the tokens
    1381             :   // inside of it.
    1382             :   ENVELOPE,
    1383             :   // We've reached the end there is nothing else to read.
    1384             :   DONE,
    1385             : };
    1386             : 
    1387             : // CBORTokenizer segments a CBOR message, presenting the tokens therein as
    1388             : // numbers, strings, etc. This is not a complete CBOR parser, but makes it much
    1389             : // easier to implement one (e.g. ParseCBOR, above). It can also be used to parse
    1390             : // messages partially.
    1391             : class CBORTokenizer {
    1392             :  public:
    1393             :   explicit CBORTokenizer(span<uint8_t> bytes);
    1394             :   ~CBORTokenizer();
    1395             : 
    1396             :   // Identifies the current token that we're looking at,
    1397             :   // or ERROR_VALUE (in which ase ::Status() has details)
    1398             :   // or DONE (if we're past the last token).
    1399             :   CBORTokenTag TokenTag() const;
    1400             : 
    1401             :   // Advances to the next token.
    1402             :   void Next();
    1403             :   // Can only be called if TokenTag() == CBORTokenTag::ENVELOPE.
    1404             :   // While Next() would skip past the entire envelope / what it's
    1405             :   // wrapping, EnterEnvelope positions the cursor inside of the envelope,
    1406             :   // letting the client explore the nested structure.
    1407             :   void EnterEnvelope();
    1408             : 
    1409             :   // If TokenTag() is CBORTokenTag::ERROR_VALUE, then Status().error describes
    1410             :   // the error more precisely; otherwise it'll be set to Error::OK.
    1411             :   // In either case, Status().pos is the current position.
    1412             :   struct Status Status() const;
    1413             : 
    1414             :   // The following methods retrieve the token values. They can only
    1415             :   // be called if TokenTag() matches.
    1416             : 
    1417             :   // To be called only if ::TokenTag() == CBORTokenTag::INT32.
    1418             :   int32_t GetInt32() const;
    1419             : 
    1420             :   // To be called only if ::TokenTag() == CBORTokenTag::DOUBLE.
    1421             :   double GetDouble() const;
    1422             : 
    1423             :   // To be called only if ::TokenTag() == CBORTokenTag::STRING8.
    1424             :   span<uint8_t> GetString8() const;
    1425             : 
    1426             :   // Wire representation for STRING16 is low byte first (little endian).
    1427             :   // To be called only if ::TokenTag() == CBORTokenTag::STRING16.
    1428             :   span<uint8_t> GetString16WireRep() const;
    1429             : 
    1430             :   // To be called only if ::TokenTag() == CBORTokenTag::BINARY.
    1431             :   span<uint8_t> GetBinary() const;
    1432             : 
    1433             :  private:
    1434             :   void ReadNextToken(bool enter_envelope);
    1435             :   void SetToken(CBORTokenTag token, std::ptrdiff_t token_byte_length);
    1436             :   void SetError(Error error);
    1437             : 
    1438             :   span<uint8_t> bytes_;
    1439             :   CBORTokenTag token_tag_;
    1440             :   struct Status status_;
    1441             :   std::ptrdiff_t token_byte_length_;
    1442             :   cbor::MajorType token_start_type_;
    1443             :   uint64_t token_start_internal_value_;
    1444             : };
    1445             : 
    1446             : void DumpCBOR(span<uint8_t> cbor);
    1447             : 
    1448             : 
    1449             : } // namespace v8_inspector
    1450             : } // namespace protocol
    1451             : #endif // !defined(v8_inspector_protocol_CBOR_h)

Generated by: LCOV version 1.10