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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: blimp/net/helium/syncable_primitive_serializer.cc
diff --git a/blimp/net/helium/syncable_primitive_serializer.cc b/blimp/net/helium/syncable_primitive_serializer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b8c91e096411f5ba9edca6823964f24c229b3dc0
--- /dev/null
+++ b/blimp/net/helium/syncable_primitive_serializer.cc
@@ -0,0 +1,40 @@
+// Copyright 2016 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 "blimp/net/helium/syncable_primitive_serializer.h"
+
+#include <string>
+
Kevin M 2016/10/17 22:19:45 stdint.h?
steimel 2016/10/18 23:53:20 Done.
+#include "third_party/protobuf/src/google/protobuf/io/coded_stream.h"
+
+namespace blimp {
+
+void SyncablePrimitiveSerializer::Serialize(
+ const int32_t& value,
+ google::protobuf::io::CodedOutputStream* output_stream) {
+ output_stream->WriteVarint32((uint32_t)value);
+}
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.
+bool SyncablePrimitiveSerializer::Deserialize(
+ google::protobuf::io::CodedInputStream* input_stream,
+ int32_t* value) {
+ 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.
+}
+
+void SyncablePrimitiveSerializer::Serialize(
+ const std::string& value,
+ google::protobuf::io::CodedOutputStream* output_stream) {
+ output_stream->WriteVarint32(value.length());
+ output_stream->WriteString(value);
+}
+bool SyncablePrimitiveSerializer::Deserialize(
+ google::protobuf::io::CodedInputStream* input_stream,
+ std::string* value) {
+ uint32_t length;
+ 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.
+ return input_stream->ReadString(value, length);
+ }
+ return false;
+}
+
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698