chromium/third_party/blink/renderer/platform/mojo/string16_mojom_traits.h

// Copyright 2016 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_MOJO_STRING16_MOJOM_TRAITS_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_MOJO_STRING16_MOJOM_TRAITS_H_

#include <string>

#include "base/containers/span.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "mojo/public/mojom/base/string16.mojom-blink.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"

namespace mojo_base {
class BigBuffer;
}

namespace mojo {

// WTF::String stores string data as 8-bit strings if only Latin-1 characters
// are present. During Mojo serialization, this helper provides a scratch buffer
// that can be used for converting an 8-bit string to a 16-bit string.
class PLATFORM_EXPORT MaybeOwnedString16 {};

template <>
struct PLATFORM_EXPORT ArrayTraits<MaybeOwnedString16> {};

template <>
struct PLATFORM_EXPORT
    StructTraits<mojo_base::mojom::String16DataView, WTF::String> {};

template <>
struct PLATFORM_EXPORT
    StructTraits<mojo_base::mojom::BigString16DataView, WTF::String> {};

}  // namespace mojo

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_MOJO_STRING16_MOJOM_TRAITS_H_