Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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/wtf_string_serialization.h" | |
| 6 | |
| 7 #include <string.h> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "third_party/WebKit/Source/wtf/text/WTFString.h" | |
| 11 | |
| 12 namespace WTF { | |
| 13 | |
| 14 size_t GetSerializedSize_(const WTF::String& input) { | |
| 15 if (input.isNull()) | |
| 16 return 0; | |
| 17 | |
| 18 DCHECK(input.is8Bit()); | |
|
haraken
2016/03/01 00:40:54
From the perspective of Blink, in common cases we
yzshen1
2016/03/01 00:51:53
If the receiver doesn't care whether the string wa
haraken
2016/03/01 01:56:46
Elliott: Do you have any preference on this?
esprehn
2016/03/01 02:03:32
wtf::String is 16 bit for many cases, the 8 bit st
yzshen1
2016/03/01 17:32:02
Mojo string is 8 bit but not enforced to be utf8.
| |
| 19 return mojo::internal::Align(sizeof(mojo::internal::String_Data) + | |
| 20 input.length()); | |
| 21 } | |
| 22 | |
| 23 void Serialize_(const WTF::String& input, | |
| 24 mojo::internal::Buffer* buf, | |
| 25 mojo::internal::String_Data** output) { | |
| 26 if (input.isNull()) { | |
| 27 *output = nullptr; | |
| 28 return; | |
| 29 } | |
| 30 | |
| 31 DCHECK(input.is8Bit()); | |
| 32 mojo::internal::String_Data* result = | |
| 33 mojo::internal::String_Data::New(input.length(), buf); | |
| 34 if (result) | |
| 35 memcpy(result->storage(), input.characters8(), input.length()); | |
| 36 *output = result; | |
| 37 } | |
| 38 | |
| 39 bool Deserialize_(mojo::internal::String_Data* input, | |
| 40 WTF::String* output, | |
| 41 mojo::internal::SerializationContext* context) { | |
| 42 if (input) { | |
| 43 WTF::String result(input->storage(), input->size()); | |
| 44 output->swap(result); | |
| 45 } else if (!output->isNull()) { | |
| 46 WTF::String result; | |
| 47 output->swap(result); | |
| 48 } | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 } // namespace WTF | |
| OLD | NEW |