Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/shared/Communication.h

Issue 4806567450902528: Issue 1794 - add handling of std::vector<std::string> by Communication::{Input,Output}Buffer (Closed)
Patch Set: Created Dec. 19, 2014, 9:42 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/CommunicationTest.cpp » ('j') | test/CommunicationTest.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/shared/Communication.h
diff --git a/src/shared/Communication.h b/src/shared/Communication.h
index 9c9e2cde2ae2e2dc4d2c48279e3b862f6b370179..4caa442dfbfeef7abcb042709cdf84d07366476e 100644
--- a/src/shared/Communication.h
+++ b/src/shared/Communication.h
@@ -38,7 +38,7 @@ namespace Communication
PROC_COMPARE_VERSIONS
};
enum ValueType : uint32_t {
- TYPE_PROC, TYPE_STRING, TYPE_WSTRING, TYPE_INT64, TYPE_INT32, TYPE_BOOL
+ TYPE_PROC, TYPE_STRING, TYPE_WSTRING, TYPE_INT64, TYPE_INT32, TYPE_BOOL, TYPE_STRINGS
Eric 2015/01/13 16:20:45 We should use TYPE_WSTRINGS. The string type used
sergei 2015/01/27 15:28:39 I'm confused, we recently accepted https://issues.
};
typedef uint32_t SizeType;
@@ -59,6 +59,7 @@ namespace Communication
InputBuffer& operator>>(int64_t& value) { return Read(value, TYPE_INT64); }
InputBuffer& operator>>(int32_t& value) { return Read(value, TYPE_INT32); }
InputBuffer& operator>>(bool& value) { return Read(value, TYPE_BOOL); }
+ InputBuffer& operator>>(std::vector<std::string>& value) { return ReadStrings(value); }
InputBuffer& operator=(const InputBuffer& copy)
{
hasType = copy.hasType;
@@ -91,6 +92,21 @@ namespace Communication
return *this;
}
+ InputBuffer& ReadStrings(std::vector<std::string>& value)
Eric 2015/01/13 16:20:45 This should be a template function parallel to Rea
+ {
+ value.clear();
+ CheckType(ValueType::TYPE_STRINGS);
+
+ SizeType length;
+ ReadBinary(length);
+ value.resize(length);
+ for (SizeType i = 0; i < length; ++i)
+ {
+ operator>>(value[i]);
+ }
+ return *this;
+ }
+
template<class T>
InputBuffer& Read(T& value, ValueType expectedType)
{
@@ -127,6 +143,7 @@ namespace Communication
OutputBuffer& operator<<(int64_t value) { return Write(value, TYPE_INT64); }
OutputBuffer& operator<<(int32_t value) { return Write(value, TYPE_INT32); }
OutputBuffer& operator<<(bool value) { return Write(value, TYPE_BOOL); }
+ OutputBuffer& operator<<(const std::vector<std::string>& value) { return WriteStrings(value); }
private:
std::ostringstream buffer;
@@ -148,6 +165,17 @@ namespace Communication
return *this;
}
+ OutputBuffer& WriteStrings(const std::vector<std::string>& value)
+ {
+ WriteBinary(ValueType::TYPE_STRINGS);
+ WriteBinary(static_cast<SizeType>(value.size()));
+ for (const auto& str : value)
+ {
+ operator<<(str);
+ }
+ return *this;
+ }
+
template<class T>
OutputBuffer& Write(const T value, ValueType type)
{
« no previous file with comments | « no previous file | test/CommunicationTest.cpp » ('j') | test/CommunicationTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld