157 lines
4.7 KiB
C++
Executable File
157 lines
4.7 KiB
C++
Executable File
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef NET_INTERFACES_IP_ADDRESS_MOJOM_SHARED_H_
|
|
#define NET_INTERFACES_IP_ADDRESS_MOJOM_SHARED_H_
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <functional>
|
|
#include <ostream>
|
|
#include <type_traits>
|
|
#include <utility>
|
|
|
|
#include "base/compiler_specific.h"
|
|
#include "base/containers/flat_map.h"
|
|
#include "mojo/public/cpp/bindings/array_data_view.h"
|
|
#include "mojo/public/cpp/bindings/enum_traits.h"
|
|
#include "mojo/public/cpp/bindings/interface_data_view.h"
|
|
#include "mojo/public/cpp/bindings/lib/bindings_internal.h"
|
|
#include "mojo/public/cpp/bindings/lib/serialization.h"
|
|
#include "mojo/public/cpp/bindings/map_data_view.h"
|
|
#include "mojo/public/cpp/bindings/string_data_view.h"
|
|
#include "net/interfaces/ip_address.mojom-shared-internal.h"
|
|
|
|
#include "mojo/public/cpp/bindings/lib/interface_serialization.h"
|
|
|
|
|
|
#include "mojo/public/cpp/bindings/native_enum.h"
|
|
#include "mojo/public/cpp/bindings/lib/native_struct_serialization.h"
|
|
|
|
|
|
namespace net {
|
|
namespace interfaces {
|
|
class IPAddressDataView;
|
|
|
|
|
|
|
|
} // namespace interfaces
|
|
} // namespace net
|
|
|
|
namespace mojo {
|
|
namespace internal {
|
|
|
|
template <>
|
|
struct MojomTypeTraits<::net::interfaces::IPAddressDataView> {
|
|
using Data = ::net::interfaces::internal::IPAddress_Data;
|
|
using DataAsArrayElement = Pointer<Data>;
|
|
static constexpr MojomTypeCategory category = MojomTypeCategory::STRUCT;
|
|
};
|
|
|
|
} // namespace internal
|
|
} // namespace mojo
|
|
|
|
|
|
namespace net {
|
|
namespace interfaces {
|
|
class IPAddressDataView {
|
|
public:
|
|
IPAddressDataView() {}
|
|
|
|
IPAddressDataView(
|
|
internal::IPAddress_Data* data,
|
|
mojo::internal::SerializationContext* context)
|
|
: data_(data), context_(context) {}
|
|
|
|
bool is_null() const { return !data_; }
|
|
inline void GetAddressBytesDataView(
|
|
mojo::ArrayDataView<uint8_t>* output);
|
|
|
|
template <typename UserType>
|
|
WARN_UNUSED_RESULT bool ReadAddressBytes(UserType* output) {
|
|
auto* pointer = data_->address_bytes.Get();
|
|
return mojo::internal::Deserialize<mojo::ArrayDataView<uint8_t>>(
|
|
pointer, output, context_);
|
|
}
|
|
private:
|
|
internal::IPAddress_Data* data_ = nullptr;
|
|
mojo::internal::SerializationContext* context_ = nullptr;
|
|
};
|
|
|
|
|
|
|
|
} // namespace interfaces
|
|
} // namespace net
|
|
|
|
namespace std {
|
|
|
|
} // namespace std
|
|
|
|
namespace mojo {
|
|
|
|
|
|
namespace internal {
|
|
|
|
template <typename MaybeConstUserType>
|
|
struct Serializer<::net::interfaces::IPAddressDataView, MaybeConstUserType> {
|
|
using UserType = typename std::remove_const<MaybeConstUserType>::type;
|
|
using Traits = StructTraits<::net::interfaces::IPAddressDataView, UserType>;
|
|
|
|
static void Serialize(MaybeConstUserType& input,
|
|
Buffer* buffer,
|
|
::net::interfaces::internal::IPAddress_Data::BufferWriter* output,
|
|
SerializationContext* context) {
|
|
if (CallIsNullIfExists<Traits>(input))
|
|
return;
|
|
void* custom_context = CustomContextHelper<Traits>::SetUp(input, context);
|
|
(*output).Allocate(buffer);
|
|
decltype(CallWithContext(Traits::address_bytes, input, custom_context)) in_address_bytes = CallWithContext(Traits::address_bytes, input, custom_context);
|
|
typename decltype((*output)->address_bytes)::BaseType::BufferWriter
|
|
address_bytes_writer;
|
|
const mojo::internal::ContainerValidateParams address_bytes_validate_params(
|
|
0, false, nullptr);
|
|
mojo::internal::Serialize<mojo::ArrayDataView<uint8_t>>(
|
|
in_address_bytes, buffer, &address_bytes_writer, &address_bytes_validate_params,
|
|
context);
|
|
(*output)->address_bytes.Set(
|
|
address_bytes_writer.is_null() ? nullptr : address_bytes_writer.data());
|
|
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
|
|
(*output)->address_bytes.is_null(),
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
|
|
"null address_bytes in IPAddress struct");
|
|
CustomContextHelper<Traits>::TearDown(input, custom_context);
|
|
}
|
|
|
|
static bool Deserialize(::net::interfaces::internal::IPAddress_Data* input,
|
|
UserType* output,
|
|
SerializationContext* context) {
|
|
if (!input)
|
|
return CallSetToNullIfExists<Traits>(output);
|
|
|
|
::net::interfaces::IPAddressDataView data_view(input, context);
|
|
return Traits::Read(data_view, output);
|
|
}
|
|
};
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace mojo
|
|
|
|
|
|
namespace net {
|
|
namespace interfaces {
|
|
|
|
inline void IPAddressDataView::GetAddressBytesDataView(
|
|
mojo::ArrayDataView<uint8_t>* output) {
|
|
auto pointer = data_->address_bytes.Get();
|
|
*output = mojo::ArrayDataView<uint8_t>(pointer, context_);
|
|
}
|
|
|
|
|
|
|
|
} // namespace interfaces
|
|
} // namespace net
|
|
|
|
#endif // NET_INTERFACES_IP_ADDRESS_MOJOM_SHARED_H_
|