OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/public/cpp/bindings/lib/string_serialization.h" |
| 6 |
| 7 #include <string.h> |
| 8 |
| 9 namespace mojo { |
| 10 |
| 11 size_t GetSerializedSize_(const String& input) { |
| 12 if (!input) |
| 13 return 0; |
| 14 return internal::Align(sizeof(internal::String_Data) + input.size()); |
| 15 } |
| 16 |
| 17 void Serialize_(const String& input, internal::Buffer* buf, |
| 18 internal::String_Data** output) { |
| 19 if (input) { |
| 20 internal::String_Data* result = |
| 21 internal::String_Data::New(input.size(), buf); |
| 22 memcpy(result->storage(), input.data(), input.size()); |
| 23 *output = result; |
| 24 } else { |
| 25 *output = NULL; |
| 26 } |
| 27 } |
| 28 |
| 29 void Deserialize_(internal::String_Data* input, String* output) { |
| 30 if (input) { |
| 31 String result(input->storage(), input->size()); |
| 32 result.Swap(output); |
| 33 } else { |
| 34 output->reset(); |
| 35 } |
| 36 } |
| 37 |
| 38 } // namespace mojo |
OLD | NEW |