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

Side by Side Diff: third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource.h

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years 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
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 use_lower_camel_for_enums_ = value; 110 use_lower_camel_for_enums_ = value;
111 } 111 }
112 112
113 // Sets the max recursion depth of proto message to be deserialized. Proto 113 // Sets the max recursion depth of proto message to be deserialized. Proto
114 // messages over this depth will fail to be deserialized. 114 // messages over this depth will fail to be deserialized.
115 // Default value is 64. 115 // Default value is 64.
116 void set_max_recursion_depth(int max_depth) { 116 void set_max_recursion_depth(int max_depth) {
117 max_recursion_depth_ = max_depth; 117 max_recursion_depth_ = max_depth;
118 } 118 }
119 119
120
120 protected: 121 protected:
121 // Writes a proto2 Message to the ObjectWriter. When the given end_tag is 122 // Writes a proto2 Message to the ObjectWriter. When the given end_tag is
122 // found this method will complete, allowing it to be used for parsing both 123 // found this method will complete, allowing it to be used for parsing both
123 // nested messages (end with 0) and nested groups (end with group end tag). 124 // nested messages (end with 0) and nested groups (end with group end tag).
124 // The include_start_and_end parameter allows this method to be called when 125 // The include_start_and_end parameter allows this method to be called when
125 // already inside of an object, and skip calling StartObject and EndObject. 126 // already inside of an object, and skip calling StartObject and EndObject.
126 virtual util::Status WriteMessage(const google::protobuf::Type& descriptor, 127 virtual util::Status WriteMessage(const google::protobuf::Type& descriptor,
127 StringPiece name, const uint32 end_tag, 128 StringPiece name, const uint32 end_tag,
128 bool include_start_and_end, 129 bool include_start_and_end,
129 ObjectWriter* ow) const; 130 ObjectWriter* ow) const;
130 131
132 // Renders a repeating field (packed or unpacked). Returns the next tag after
133 // reading all sequential repeating elements. The caller should use this tag
134 // before reading more tags from the stream.
135 virtual util::StatusOr<uint32> RenderList(
136 const google::protobuf::Field* field, StringPiece name, uint32 list_tag,
137 ObjectWriter* ow) const;
138
139 // Looks up a field and verify its consistency with wire type in tag.
140 const google::protobuf::Field* FindAndVerifyField(
141 const google::protobuf::Type& type, uint32 tag) const;
142
143 // Renders a field value to the ObjectWriter.
144 util::Status RenderField(const google::protobuf::Field* field,
145 StringPiece field_name, ObjectWriter* ow) const;
146
147 // Reads field value according to Field spec in 'field' and returns the read
148 // value as string. This only works for primitive datatypes (no message
149 // types).
150 const string ReadFieldValueAsString(
151 const google::protobuf::Field& field) const;
152
153
131 private: 154 private:
132 ProtoStreamObjectSource(google::protobuf::io::CodedInputStream* stream, 155 ProtoStreamObjectSource(google::protobuf::io::CodedInputStream* stream,
133 const TypeInfo* typeinfo, 156 const TypeInfo* typeinfo,
134 const google::protobuf::Type& type); 157 const google::protobuf::Type& type);
135 // Function that renders a well known type with a modified behavior. 158 // Function that renders a well known type with a modified behavior.
136 typedef util::Status (*TypeRenderer)(const ProtoStreamObjectSource*, 159 typedef util::Status (*TypeRenderer)(const ProtoStreamObjectSource*,
137 const google::protobuf::Type&, 160 const google::protobuf::Type&,
138 StringPiece, ObjectWriter*); 161 StringPiece, ObjectWriter*);
139 162
140 // Looks up a field and verify its consistency with wire type in tag.
141 const google::protobuf::Field* FindAndVerifyField(
142 const google::protobuf::Type& type, uint32 tag) const;
143
144 // TODO(skarvaje): Mark these methods as non-const as they modify internal 163 // TODO(skarvaje): Mark these methods as non-const as they modify internal
145 // state (stream_). 164 // state (stream_).
146 // 165 //
147 // Renders a repeating field (packed or unpacked).
148 // Returns the next tag after reading all sequential repeating elements. The
149 // caller should use this tag before reading more tags from the stream.
150 util::StatusOr<uint32> RenderList(const google::protobuf::Field* field,
151 StringPiece name, uint32 list_tag,
152 ObjectWriter* ow) const;
153 // Renders a NWP map. 166 // Renders a NWP map.
154 // Returns the next tag after reading all map entries. The caller should use 167 // Returns the next tag after reading all map entries. The caller should use
155 // this tag before reading more tags from the stream. 168 // this tag before reading more tags from the stream.
156 util::StatusOr<uint32> RenderMap(const google::protobuf::Field* field, 169 util::StatusOr<uint32> RenderMap(const google::protobuf::Field* field,
157 StringPiece name, uint32 list_tag, 170 StringPiece name, uint32 list_tag,
158 ObjectWriter* ow) const; 171 ObjectWriter* ow) const;
159 172
160 // Renders a packed repeating field. A packed field is stored as: 173 // Renders a packed repeating field. A packed field is stored as:
161 // {tag length item1 item2 item3} instead of the less efficient 174 // {tag length item1 item2 item3} instead of the less efficient
162 // {tag item1 tag item2 tag item3}. 175 // {tag item1 tag item2 tag item3}.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // Render the "FieldMask" type. 239 // Render the "FieldMask" type.
227 static util::Status RenderFieldMask(const ProtoStreamObjectSource* os, 240 static util::Status RenderFieldMask(const ProtoStreamObjectSource* os,
228 const google::protobuf::Type& type, 241 const google::protobuf::Type& type,
229 StringPiece name, ObjectWriter* ow); 242 StringPiece name, ObjectWriter* ow);
230 243
231 static hash_map<string, TypeRenderer>* renderers_; 244 static hash_map<string, TypeRenderer>* renderers_;
232 static void InitRendererMap(); 245 static void InitRendererMap();
233 static void DeleteRendererMap(); 246 static void DeleteRendererMap();
234 static TypeRenderer* FindTypeRenderer(const string& type_url); 247 static TypeRenderer* FindTypeRenderer(const string& type_url);
235 248
236 // Renders a field value to the ObjectWriter.
237 util::Status RenderField(const google::protobuf::Field* field,
238 StringPiece field_name, ObjectWriter* ow) const;
239
240 // Same as above but renders all non-message field types. Callers don't call 249 // Same as above but renders all non-message field types. Callers don't call
241 // this function directly. They just use RenderField. 250 // this function directly. They just use RenderField.
242 util::Status RenderNonMessageField(const google::protobuf::Field* field, 251 util::Status RenderNonMessageField(const google::protobuf::Field* field,
243 StringPiece field_name, 252 StringPiece field_name,
244 ObjectWriter* ow) const; 253 ObjectWriter* ow) const;
245 254
246 255
247 // Reads field value according to Field spec in 'field' and returns the read
248 // value as string. This only works for primitive datatypes (no message
249 // types).
250 const string ReadFieldValueAsString(
251 const google::protobuf::Field& field) const;
252
253 // Utility function to detect proto maps. The 'field' MUST be repeated. 256 // Utility function to detect proto maps. The 'field' MUST be repeated.
254 bool IsMap(const google::protobuf::Field& field) const; 257 bool IsMap(const google::protobuf::Field& field) const;
255 258
256 // Utility to read int64 and int32 values from a message type in stream_. 259 // Utility to read int64 and int32 values from a message type in stream_.
257 // Used for reading google.protobuf.Timestamp and Duration messages. 260 // Used for reading google.protobuf.Timestamp and Duration messages.
258 std::pair<int64, int32> ReadSecondsAndNanos( 261 std::pair<int64, int32> ReadSecondsAndNanos(
259 const google::protobuf::Type& type) const; 262 const google::protobuf::Type& type) const;
260 263
261 // Helper function to check recursion depth and increment it. It will return 264 // Helper function to check recursion depth and increment it. It will return
262 // Status::OK if the current depth is allowed. Otherwise an error is returned. 265 // Status::OK if the current depth is allowed. Otherwise an error is returned.
263 // type_name and field_name are used for error reporting. 266 // type_name and field_name are used for error reporting.
264 util::Status IncrementRecursionDepth(StringPiece type_name, 267 util::Status IncrementRecursionDepth(StringPiece type_name,
265 StringPiece field_name) const; 268 StringPiece field_name) const;
266 269
267 // Input stream to read from. Ownership rests with the caller. 270 // Input stream to read from. Ownership rests with the caller.
268 google::protobuf::io::CodedInputStream* stream_; 271 google::protobuf::io::CodedInputStream* stream_;
269 272
270 // Type information for all the types used in the descriptor. Used to find 273 // Type information for all the types used in the descriptor. Used to find
271 // google::protobuf::Type of nested messages/enums. 274 // google::protobuf::Type of nested messages/enums.
272 const TypeInfo* typeinfo_; 275 const TypeInfo* typeinfo_;
276
273 // Whether this class owns the typeinfo_ object. If true the typeinfo_ object 277 // Whether this class owns the typeinfo_ object. If true the typeinfo_ object
274 // should be deleted in the destructor. 278 // should be deleted in the destructor.
275 bool own_typeinfo_; 279 bool own_typeinfo_;
276 280
277 // google::protobuf::Type of the message source. 281 // google::protobuf::Type of the message source.
278 const google::protobuf::Type& type_; 282 const google::protobuf::Type& type_;
279 283
280 284
281 // Whether to render enums using lowerCamelCase. Defaults to false. 285 // Whether to render enums using lowerCamelCase. Defaults to false.
282 bool use_lower_camel_for_enums_; 286 bool use_lower_camel_for_enums_;
283 287
284 // Tracks current recursion depth. 288 // Tracks current recursion depth.
285 mutable int recursion_depth_; 289 mutable int recursion_depth_;
286 290
287 // Maximum allowed recursion depth. 291 // Maximum allowed recursion depth.
288 int max_recursion_depth_; 292 int max_recursion_depth_;
289 293
294 // Whether to render unknown fields.
295 bool render_unknown_fields_;
296
297 // Whether to add trailing zeros for timestamp and duration.
298 bool add_trailing_zeros_for_timestamp_and_duration_;
299
290 GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(ProtoStreamObjectSource); 300 GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(ProtoStreamObjectSource);
291 }; 301 };
292 302
293 } // namespace converter 303 } // namespace converter
294 } // namespace util 304 } // namespace util
295 } // namespace protobuf 305 } // namespace protobuf
296 306
297 } // namespace google 307 } // namespace google
298 #endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_PROTOSTREAM_OBJECTSOURCE_H__ 308 #endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_PROTOSTREAM_OBJECTSOURCE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698