Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(944)

Unified Diff: src/google/protobuf/wire_format_lite_inl.h

Issue 4077052: Implement generated visitor classes in C++. Base URL: http://protobuf.googlecode.com/svn/trunk/
Patch Set: Created 13 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/google/protobuf/wire_format_lite_inl.h
===================================================================
--- src/google/protobuf/wire_format_lite_inl.h (revision 374)
+++ src/google/protobuf/wire_format_lite_inl.h (working copy)
@@ -285,7 +285,7 @@
return true;
}
-// Specializations of ReadRepeatedPrimitive for the fixed size types, which use
+// Specializations of ReadRepeatedPrimitive for the fixed size types, which use
// the optimized code path.
#define READ_REPEATED_FIXED_SIZE_PRIMITIVE(CPPTYPE, DECLARED_TYPE) \
template <> \
@@ -334,6 +334,22 @@
return true;
}
+template <typename CType, enum WireFormatLite::FieldType DeclaredType,
+ typename VisitorType, void (VisitorType::*visit_method)(CType value)>
+inline bool WireFormatLite::ReadPackedPrimitiveToVisitor(
+ io::CodedInputStream* input, VisitorType* visitor) {
+ uint32 length;
+ if (!input->ReadVarint32(&length)) return false;
+ io::CodedInputStream::Limit limit = input->PushLimit(length);
+ while (input->BytesUntilLimit() > 0) {
+ CType value;
+ if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
+ (visitor->*visit_method)(value);
+ }
+ input->PopLimit(limit);
+ return true;
+}
+
template <typename CType, enum WireFormatLite::FieldType DeclaredType>
bool WireFormatLite::ReadPackedPrimitiveNoInline(io::CodedInputStream* input,
RepeatedField<CType>* values) {
@@ -411,6 +427,55 @@
return true;
}
+template<typename VisitorType, typename GuideType, typename ReaderType,
+ bool (VisitorType::*visit_method)(GuideType* guide)>
+inline bool WireFormatLite::ReadGroupToVisitor(int field_number,
+ io::CodedInputStream* input,
+ VisitorType* visitor) {
+ if (!input->IncrementRecursionDepth()) return false;
+
+ {
+ ReaderType reader(input);
+ if (!(visitor->*visit_method)(&reader)) return false;
+ if (!reader.IsUsed()) {
+ SkipMessage(input);
+ }
+ }
+
+ input->DecrementRecursionDepth();
+ // Make sure the last thing read was an end tag for this group.
+ if (!input->LastTagWas(MakeTag(field_number, WIRETYPE_END_GROUP))) {
+ return false;
+ }
+ return true;
+}
+template<typename VisitorType, typename GuideType, typename ReaderType,
+ bool (VisitorType::*visit_method)(GuideType* guide)>
+inline bool WireFormatLite::ReadMessageToVisitor(io::CodedInputStream* input,
+ VisitorType* visitor) {
+ uint32 length;
+ if (!input->ReadVarint32(&length)) return false;
+ if (!input->IncrementRecursionDepth()) return false;
+ io::CodedInputStream::Limit limit = input->PushLimit(length);
+
+ {
+ ReaderType reader(input);
+ if (!(visitor->*visit_method)(&reader)) return false;
+ if (!reader.IsUsed()) {
+ input->Skip(input->BytesUntilLimit());
+ // Force ConsumedEntireMessage() to return true below.
+ input->ReadTag();
+ }
+ }
+
+ // Make sure that parsing stopped when the limit was hit, not at an endgroup
+ // tag.
+ if (!input->ConsumedEntireMessage()) return false;
+ input->PopLimit(limit);
+ input->DecrementRecursionDepth();
+ return true;
+}
+
// ===================================================================
inline void WireFormatLite::WriteTag(int field_number, WireType type,
@@ -495,6 +560,28 @@
value.MessageType_WorkAroundCppLookupDefect::SerializeWithCachedSizes(output);
}
+template<typename MessageType, typename GuideType, typename WriterType>
+inline bool WireFormatLite::WriteGroupFromGuide(int field_number,
+ GuideType* guide,
+ io::CodedOutputStream* output) {
+ WriteTag(field_number, WIRETYPE_START_GROUP, output);
+ WriterType writer(output);
+ bool result = guide->Accept(&writer);
+ WriteTag(field_number, WIRETYPE_END_GROUP, output);
+ return result;
+}
+template<typename MessageType, typename GuideType, typename WriterType>
+inline bool WireFormatLite::WriteMessageFromGuide(int field_number,
+ GuideType* guide,
+ io::CodedOutputStream* output) {
+ MessageType message;
jasonh 2011/02/10 19:35:50 Why does this method copy the message from the gui
+ bool result = guide->Fill(&message);
+ WriteTag(field_number, WIRETYPE_LENGTH_DELIMITED, output);
+ output->WriteVarint32(message.MessageType::ByteSize());
+ message.MessageType::SerializeWithCachedSizes(output);
+ return result;
+}
+
// ===================================================================
inline uint8* WireFormatLite::WriteTagToArray(int field_number,
« src/google/protobuf/compiler/plugin.pb.cc ('K') | « src/google/protobuf/wire_format_lite.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b