chromium/mojo/public/cpp/bindings/lib/bindings_internal.h

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_
#define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_

#include <stdint.h>

#include <functional>
#include <optional>
#include <type_traits>
#include <utility>

#include "base/logging.h"
#include "mojo/public/cpp/bindings/enum_traits.h"
#include "mojo/public/cpp/bindings/interface_id.h"
#include "mojo/public/cpp/bindings/lib/template_util.h"
#include "mojo/public/cpp/platform/platform_handle.h"
#include "mojo/public/cpp/system/handle.h"

namespace mojo {

template <typename T>
class ArrayDataView;

template <typename T>
class AssociatedInterfacePtrInfoDataView;

template <typename T>
class AssociatedInterfaceRequestDataView;

template <typename T>
class InterfacePtrDataView;

template <typename T>
class InterfaceRequestDataView;

template <typename K, typename V>
class MapDataView;

class StringDataView;

namespace internal {

// Please note that this is a different value than |mojo::kInvalidHandleValue|,
// which is the "decoded" invalid handle.
const uint32_t kEncodedInvalidHandleValue =;

// A serialized union always takes 16 bytes:
//   4-byte size + 4-byte tag + 8-byte payload.
const uint32_t kUnionDataSize =;

template <typename T>
class Array_Data;

template <typename K, typename V>
class Map_Data;

String_Data;

inline size_t Align(size_t size) {}

inline bool IsAligned(const void* ptr) {}

// Pointers are encoded as relative offsets. The offsets are relative to the
// address of where the offset value is stored, such that the pointer may be
// recovered with the expression:
//
//   ptr = reinterpret_cast<char*>(offset) + *offset
//
// A null pointer is encoded as an offset value of 0.
//
inline void EncodePointer(const void* ptr, uint64_t* offset) {}

// Note: This function doesn't validate the encoded pointer value.
inline const void* DecodePointer(const uint64_t* offset) {}

#pragma pack(push, 1)

struct StructHeader {};
static_assert;

struct ArrayHeader {};
static_assert;

template <typename T>
struct Pointer {};
static_assert;

GenericPointer;

struct Handle_Data {};
static_assert;

struct Interface_Data {};
static_assert;

struct AssociatedEndpointHandle_Data {};
static_assert;

struct AssociatedInterface_Data {};
static_assert;

#pragma pack(pop)

template <typename T>
T FetchAndReset(T* ptr) {}

template <typename T, typename SFINAE = void>
struct IsUnionDataType : std::false_type {};

IsUnionDataType<T, typename T::MojomUnionDataType>;

enum class MojomTypeCategory : uint32_t {};

inline constexpr MojomTypeCategory operator&(MojomTypeCategory x,
                                             MojomTypeCategory y) {}

inline constexpr MojomTypeCategory operator|(MojomTypeCategory x,
                                             MojomTypeCategory y) {}

template <typename T>
struct MojomTypeTraits {};

MojomTypeTraits<std::optional<T>>;

MojomTypeTraits<ArrayDataView<T>>;

MojomTypeTraits<AssociatedInterfacePtrInfoDataView<T>>;

MojomTypeTraits<AssociatedInterfaceRequestDataView<T>>;

template <>
struct MojomTypeTraits<bool> {};

MojomTypeTraits<T>;

MojomTypeTraits<std::optional<T>>;

MojomTypeTraits<ScopedHandleBase<T>>;

template <>
struct MojomTypeTraits<PlatformHandle> {};

MojomTypeTraits<InterfacePtrDataView<T>>;

MojomTypeTraits<InterfaceRequestDataView<T>>;

MojomTypeTraits<MapDataView<K, V>>;

template <>
struct MojomTypeTraits<StringDataView> {};

template <typename T, MojomTypeCategory categories>
struct BelongsTo {};

template <typename T>
struct EnumHashImpl {};

template <typename MojomType, typename T>
T ConvertEnumValue(MojomType input) {}

template <typename MojomType, typename SFINAE = void>
struct EnumKnownValueTraits {};

EnumKnownValueTraits<MojomType, std::void_t<decltype(ToKnownEnumValue(std::declval<MojomType>()))>>;

template <typename MojomType>
MojomType ToKnownEnumValueHelper(MojomType in) {}

}  // namespace internal
}  // namespace mojo

#endif  // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_