chromium/third_party/inspector_protocol/crdtp/chromium/protocol_traits.h

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CRDTP_CHROMIUM_PROTOCOL_TYPE_TRAITS_H_
#define CRDTP_CHROMIUM_PROTOCOL_TYPE_TRAITS_H_

#include <string_view>
#include <vector>

#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"

namespace base {
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.
String;
Value;
DictionaryValue;
ListValue;

}  // namespace traits

template <>
struct CRDTP_EXPORT ProtocolTypeTraits<std::string> {};

template <>
struct CRDTP_EXPORT ProtocolTypeTraits<base::Value> {};

template <>
struct CRDTP_EXPORT ProtocolTypeTraits<traits::DictionaryValue> {};

template <>
struct CRDTP_EXPORT ProtocolTypeTraits<traits::ListValue> {};

template <typename T>
struct UniquePtrTraitsHelper {};

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 {};

template <>
struct CRDTP_EXPORT ProtocolTypeTraits<Binary> {};

template <>
struct detail::MaybeTypedef<Binary> {};

}  // namespace crdtp

#endif  // CRDTP_CHROMIUM_PROTOCOL_TYPE_TRAITS_H_