Index: mojo/public/cpp/bindings/lib/string_serialization.cc |
diff --git a/mojo/public/cpp/bindings/lib/string_serialization.cc b/mojo/public/cpp/bindings/lib/string_serialization.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..49a9ce3d4e793f177443aca7b706028674890516 |
--- /dev/null |
+++ b/mojo/public/cpp/bindings/lib/string_serialization.cc |
@@ -0,0 +1,31 @@ |
+// Copyright 2014 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. |
+ |
+#include "mojo/public/cpp/bindings/lib/string_serialization.h" |
+ |
+#include <string.h> |
+ |
+#include "mojo/public/cpp/bindings/lib/array_internal.h" |
yzshen1
2014/05/27 22:16:59
nit: the .h file has already included it.
|
+ |
+namespace mojo { |
+ |
+size_t GetSerializedSize_(const String& input) { |
+ return internal::Align(sizeof(internal::String_Data) + input.size()); |
+} |
+ |
+void Serialize_(const String& input, internal::Buffer* buf, |
+ internal::String_Data** output) { |
+ internal::String_Data* result = internal::String_Data::New(input.size(), buf); |
yzshen1
2014/05/27 22:16:59
Maybe we need to check whether input is null and s
|
+ memcpy(result->storage(), input.data(), input.size()); |
+ *output = result; |
+} |
+ |
+void Deserialize_(internal::String_Data* input, String* output) { |
+ if (input) { |
+ String result(input->storage(), input->size()); |
+ result.Swap(output); |
+ } |
+} |
+ |
+} // namespace mojo |