diff options
Diffstat (limited to 'chromium/third_party/inspector_protocol/crdtp/chromium/protocol_traits.h')
-rw-r--r-- | chromium/third_party/inspector_protocol/crdtp/chromium/protocol_traits.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/chromium/third_party/inspector_protocol/crdtp/chromium/protocol_traits.h b/chromium/third_party/inspector_protocol/crdtp/chromium/protocol_traits.h index 4f9386210db..a4e9b96e70c 100644 --- a/chromium/third_party/inspector_protocol/crdtp/chromium/protocol_traits.h +++ b/chromium/third_party/inspector_protocol/crdtp/chromium/protocol_traits.h @@ -5,6 +5,7 @@ #include "base/memory/ref_counted_memory.h" #include "base/memory/scoped_refptr.h" +#include "base/values.h" #include "third_party/inspector_protocol/crdtp/protocol_core.h" #include "third_party/inspector_protocol/crdtp/serializable.h" @@ -15,12 +16,63 @@ class Value; namespace crdtp { class Serializable; +namespace traits { + +// TODO(caseq): these should eventually be replaced with configurable +// types in protocol_config.json, so we can generate code with direct +// types rather than aliases, but for the time being, this is our way +// to specify the type mapping to the rest of the generated code. +using String = std::string; +using Value = base::Value; +using DictionaryValue = base::flat_map<std::string, base::Value>; +using ListValue = std::vector<base::Value>; + +} // namespace traits + template <> struct CRDTP_EXPORT ProtocolTypeTraits<std::string> { static bool Deserialize(DeserializerState* state, std::string* value); static void Serialize(const std::string& value, std::vector<uint8_t>* bytes); }; +template <> +struct CRDTP_EXPORT ProtocolTypeTraits<base::Value> { + static bool Deserialize(DeserializerState* state, base::Value* value); + static void Serialize(const base::Value& value, std::vector<uint8_t>* bytes); +}; + +template <> +struct CRDTP_EXPORT ProtocolTypeTraits<traits::DictionaryValue> { + static bool Deserialize(DeserializerState* state, + traits::DictionaryValue* value); + static void Serialize(const traits::DictionaryValue& value, + std::vector<uint8_t>* bytes); +}; + +template <typename T> +struct UniquePtrTraitsHelper { + static bool Deserialize(DeserializerState* state, std::unique_ptr<T>* value) { + auto res = std::make_unique<T>(); + if (!ProtocolTypeTraits<T>::Deserialize(state, res.get())) + return false; + *value = std::move(res); + return true; + } + static void Serialize(const std::unique_ptr<T>& value, + std::vector<uint8_t>* bytes) { + ProtocolTypeTraits<T>::Serialize(*value, bytes); + } +}; + +template <> +struct CRDTP_EXPORT ProtocolTypeTraits<std::unique_ptr<traits::DictionaryValue>> + : public UniquePtrTraitsHelper<traits::DictionaryValue> {}; + +// TODO(caseq): get rid of this, make sure Value is stored directly. +template <> +struct CRDTP_EXPORT ProtocolTypeTraits<std::unique_ptr<base::Value>> + : public UniquePtrTraitsHelper<base::Value> {}; + // A read-only sequence of uninterpreted bytes with reference-counted storage. class CRDTP_EXPORT Binary : public Serializable { public: |