summaryrefslogtreecommitdiffstats
path: root/mojo/common/common_type_converters.h
blob: 5f6e3c592099175c77f0819cc06a6816db24f1c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2013 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 MOJO_COMMON_COMMON_TYPE_CONVERTERS_H_
#define MOJO_COMMON_COMMON_TYPE_CONVERTERS_H_

#include <stdint.h>

#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
#include "mojo/common/mojo_common_export.h"
#include "mojo/public/cpp/bindings/array.h"
#include "mojo/public/cpp/bindings/string.h"
#include "mojo/public/cpp/bindings/type_converter.h"

namespace mojo {

template <>
struct MOJO_COMMON_EXPORT TypeConverter<String, base::StringPiece> {
  static String Convert(const base::StringPiece& input);
};

template <>
struct MOJO_COMMON_EXPORT TypeConverter<base::StringPiece, String> {
  static base::StringPiece Convert(const String& input);
};

template <>
struct MOJO_COMMON_EXPORT TypeConverter<String, base::string16> {
  static String Convert(const base::string16& input);
};

template <>
struct MOJO_COMMON_EXPORT TypeConverter<base::string16, String> {
  static base::string16 Convert(const String& input);
};

// TODO(erg): In the very long term, we will want to remove conversion between
// std::strings and arrays of unsigned bytes. However, there is too much code
// across chrome which uses std::string as a bag of bytes that we probably
// don't want to roll this function at each callsite.
template <>
struct MOJO_COMMON_EXPORT TypeConverter<std::string, Array<uint8_t> > {
  static std::string Convert(const Array<uint8_t>& input);
};

template <>
struct MOJO_COMMON_EXPORT TypeConverter<Array<uint8_t>, std::string> {
  static Array<uint8_t> Convert(const std::string& input);
};

}  // namespace mojo

#endif  // MOJO_COMMON_COMMON_TYPE_CONVERTERS_H_