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 "blimp/net/helium/syncable_primitive_serializer.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
|
Kevin M
2016/10/17 22:19:45
stdint.h?
steimel
2016/10/18 23:53:20
Done.
| |
| 9 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" | |
| 10 | |
| 11 namespace blimp { | |
| 12 | |
| 13 void SyncablePrimitiveSerializer::Serialize( | |
| 14 const int32_t& value, | |
| 15 google::protobuf::io::CodedOutputStream* output_stream) { | |
| 16 output_stream->WriteVarint32((uint32_t)value); | |
| 17 } | |
|
Kevin M
2016/10/17 22:19:45
Add newline between methods and use comments to gr
steimel
2016/10/18 23:53:20
Done.
| |
| 18 bool SyncablePrimitiveSerializer::Deserialize( | |
| 19 google::protobuf::io::CodedInputStream* input_stream, | |
| 20 int32_t* value) { | |
| 21 return input_stream->ReadVarint32((uint32_t*)value); | |
|
Kevin M
2016/10/17 22:19:45
Never use C-style casting. static_cast<> would wor
steimel
2016/10/18 23:53:20
Done.
| |
| 22 } | |
| 23 | |
| 24 void SyncablePrimitiveSerializer::Serialize( | |
| 25 const std::string& value, | |
| 26 google::protobuf::io::CodedOutputStream* output_stream) { | |
| 27 output_stream->WriteVarint32(value.length()); | |
| 28 output_stream->WriteString(value); | |
| 29 } | |
| 30 bool SyncablePrimitiveSerializer::Deserialize( | |
| 31 google::protobuf::io::CodedInputStream* input_stream, | |
| 32 std::string* value) { | |
| 33 uint32_t length; | |
| 34 if (input_stream->ReadVarint32(&length)) { | |
|
Kevin M
2016/10/17 22:19:45
Should we have a sanity check of some sort here? I
steimel
2016/10/18 23:53:20
Done.
| |
| 35 return input_stream->ReadString(value, length); | |
| 36 } | |
| 37 return false; | |
| 38 } | |
| 39 | |
| 40 } // namespace blimp | |
| OLD | NEW |