Index: third_party/protobuf/src/google/protobuf/wire_format.h |
diff --git a/third_party/protobuf/src/google/protobuf/wire_format.h b/third_party/protobuf/src/google/protobuf/wire_format.h |
index fc60f51bf6ded71baa09cc34a4b7a3a87e47178d..941be75ba1e2adaca25d0981f42db3127552e5e5 100644 |
--- a/third_party/protobuf/src/google/protobuf/wire_format.h |
+++ b/third_party/protobuf/src/google/protobuf/wire_format.h |
@@ -1,6 +1,6 @@ |
// Protocol Buffers - Google's data interchange format |
// Copyright 2008 Google Inc. All rights reserved. |
-// http://code.google.com/p/protobuf/ |
+// https://developers.google.com/protocol-buffers/ |
// |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
@@ -79,7 +79,7 @@ class LIBPROTOBUF_EXPORT WireFormat { |
static inline WireFormatLite::WireType WireTypeForField( |
const FieldDescriptor* field); |
- // Given a FieldSescriptor::Type return its WireType |
+ // Given a FieldDescriptor::Type return its WireType |
static inline WireFormatLite::WireType WireTypeForFieldType( |
FieldDescriptor::Type type); |
@@ -124,6 +124,62 @@ class LIBPROTOBUF_EXPORT WireFormat { |
// WireFormat::SerializeWithCachedSizes() on the same object. |
static int ByteSize(const Message& message); |
+ // ----------------------------------------------------------------- |
+ // Helpers for dealing with unknown fields |
+ |
+ // Skips a field value of the given WireType. The input should start |
+ // positioned immediately after the tag. If unknown_fields is non-NULL, |
+ // the contents of the field will be added to it. |
+ static bool SkipField(io::CodedInputStream* input, uint32 tag, |
+ UnknownFieldSet* unknown_fields); |
+ |
+ // Reads and ignores a message from the input. If unknown_fields is non-NULL, |
+ // the contents will be added to it. |
+ static bool SkipMessage(io::CodedInputStream* input, |
+ UnknownFieldSet* unknown_fields); |
+ |
+ // Read a packed enum field. If the is_valid function is not NULL, values for |
+ // which is_valid(value) returns false are appended to unknown_fields_stream. |
+ static bool ReadPackedEnumPreserveUnknowns(io::CodedInputStream* input, |
+ uint32 field_number, |
+ bool (*is_valid)(int), |
+ UnknownFieldSet* unknown_fields, |
+ RepeatedField<int>* values); |
+ |
+ // Write the contents of an UnknownFieldSet to the output. |
+ static void SerializeUnknownFields(const UnknownFieldSet& unknown_fields, |
+ io::CodedOutputStream* output); |
+ // Same as above, except writing directly to the provided buffer. |
+ // Requires that the buffer have sufficient capacity for |
+ // ComputeUnknownFieldsSize(unknown_fields). |
+ // |
+ // Returns a pointer past the last written byte. |
+ static uint8* SerializeUnknownFieldsToArray( |
+ const UnknownFieldSet& unknown_fields, |
+ uint8* target); |
+ |
+ // Same thing except for messages that have the message_set_wire_format |
+ // option. |
+ static void SerializeUnknownMessageSetItems( |
+ const UnknownFieldSet& unknown_fields, |
+ io::CodedOutputStream* output); |
+ // Same as above, except writing directly to the provided buffer. |
+ // Requires that the buffer have sufficient capacity for |
+ // ComputeUnknownMessageSetItemsSize(unknown_fields). |
+ // |
+ // Returns a pointer past the last written byte. |
+ static uint8* SerializeUnknownMessageSetItemsToArray( |
+ const UnknownFieldSet& unknown_fields, |
+ uint8* target); |
+ |
+ // Compute the size of the UnknownFieldSet on the wire. |
+ static int ComputeUnknownFieldsSize(const UnknownFieldSet& unknown_fields); |
+ |
+ // Same thing except for messages that have the message_set_wire_format |
+ // option. |
+ static int ComputeUnknownMessageSetItemsSize( |
+ const UnknownFieldSet& unknown_fields); |
+ |
// Helper functions for encoding and decoding tags. (Inlined below and in |
// _inl.h) |
@@ -132,7 +188,7 @@ class LIBPROTOBUF_EXPORT WireFormat { |
// of packed repeated fields. |
static uint32 MakeTag(const FieldDescriptor* field); |
- // Parse a single field. The input should start out positioned immidately |
+ // Parse a single field. The input should start out positioned immediately |
// after the tag. |
static bool ParseAndMergeField( |
uint32 tag, |
@@ -175,30 +231,57 @@ class LIBPROTOBUF_EXPORT WireFormat { |
const Message& message); |
enum Operation { |
- PARSE, |
- SERIALIZE, |
+ PARSE = 0, |
+ SERIALIZE = 1, |
}; |
// Verifies that a string field is valid UTF8, logging an error if not. |
+ // This function will not be called by newly generated protobuf code |
+ // but remains present to support existing code. |
static void VerifyUTF8String(const char* data, int size, Operation op); |
+ // The NamedField variant takes a field name in order to produce an |
+ // informative error message if verification fails. |
+ static void VerifyUTF8StringNamedField(const char* data, |
+ int size, |
+ Operation op, |
+ const char* field_name); |
private: |
- // Verifies that a string field is valid UTF8, logging an error if not. |
- static void VerifyUTF8StringFallback( |
- const char* data, |
- int size, |
- Operation op); |
- |
+ // Skip a MessageSet field. |
+ static bool SkipMessageSetField(io::CodedInputStream* input, |
+ uint32 field_number, |
+ UnknownFieldSet* unknown_fields); |
+ // Parse a MessageSet field. |
+ static bool ParseAndMergeMessageSetField(uint32 field_number, |
+ const FieldDescriptor* field, |
+ Message* message, |
+ io::CodedInputStream* input); |
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(WireFormat); |
}; |
+// Subclass of FieldSkipper which saves skipped fields to an UnknownFieldSet. |
+class LIBPROTOBUF_EXPORT UnknownFieldSetFieldSkipper : public FieldSkipper { |
+ public: |
+ UnknownFieldSetFieldSkipper(UnknownFieldSet* unknown_fields) |
+ : unknown_fields_(unknown_fields) {} |
+ virtual ~UnknownFieldSetFieldSkipper() {} |
+ |
+ // implements FieldSkipper ----------------------------------------- |
+ virtual bool SkipField(io::CodedInputStream* input, uint32 tag); |
+ virtual bool SkipMessage(io::CodedInputStream* input); |
+ virtual void SkipUnknownEnum(int field_number, int value); |
+ |
+ protected: |
+ UnknownFieldSet* unknown_fields_; |
+}; |
+ |
// inline methods ==================================================== |
inline WireFormatLite::WireType WireFormat::WireTypeForField( |
const FieldDescriptor* field) { |
- if (field->options().packed()) { |
+ if (field->is_packed()) { |
return WireFormatLite::WIRETYPE_LENGTH_DELIMITED; |
} else { |
return WireTypeForFieldType(field->type()); |
@@ -229,13 +312,23 @@ inline int WireFormat::TagSize(int field_number, FieldDescriptor::Type type) { |
inline void WireFormat::VerifyUTF8String(const char* data, int size, |
WireFormat::Operation op) { |
#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED |
- WireFormat::VerifyUTF8StringFallback(data, size, op); |
+ WireFormatLite::VerifyUtf8String( |
+ data, size, static_cast<WireFormatLite::Operation>(op), NULL); |
#else |
// Avoid the compiler warning about unsued variables. |
(void)data; (void)size; (void)op; |
#endif |
} |
+inline void WireFormat::VerifyUTF8StringNamedField( |
+ const char* data, int size, WireFormat::Operation op, |
+ const char* field_name) { |
+#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED |
+ WireFormatLite::VerifyUtf8String( |
+ data, size, static_cast<WireFormatLite::Operation>(op), field_name); |
+#endif |
+} |
+ |
} // namespace internal |
} // namespace protobuf |