Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: blimp/net/helium/syncable_primitive_serializer.cc

Issue 2400303002: Add LwwRegister CRDT (Closed)
Patch Set: Refactor Serializer to use overloaded methods and add unit tests. Refactor LwwRegister to not be te… Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698