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

Side by Side Diff: third_party/protobuf/src/google/protobuf/message_lite.h

Issue 1322483002: Revert https://codereview.chromium.org/1291903002 (protobuf roll). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 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 // http://code.google.com/p/protobuf/
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.
11 // * Redistributions in binary form must reproduce the above 11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer 12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the 13 // in the documentation and/or other materials provided with the
(...skipping 20 matching lines...) Expand all
34 // Sanjay Ghemawat, Jeff Dean, and others. 34 // Sanjay Ghemawat, Jeff Dean, and others.
35 // 35 //
36 // Defines MessageLite, the abstract interface implemented by all (lite 36 // Defines MessageLite, the abstract interface implemented by all (lite
37 // and non-lite) protocol message objects. 37 // and non-lite) protocol message objects.
38 38
39 #ifndef GOOGLE_PROTOBUF_MESSAGE_LITE_H__ 39 #ifndef GOOGLE_PROTOBUF_MESSAGE_LITE_H__
40 #define GOOGLE_PROTOBUF_MESSAGE_LITE_H__ 40 #define GOOGLE_PROTOBUF_MESSAGE_LITE_H__
41 41
42 #include <google/protobuf/stubs/common.h> 42 #include <google/protobuf/stubs/common.h>
43 43
44
45 namespace google { 44 namespace google {
46 namespace protobuf { 45 namespace protobuf {
47 class Arena; 46
48 namespace io { 47 namespace io {
49 class CodedInputStream; 48 class CodedInputStream;
50 class CodedOutputStream; 49 class CodedOutputStream;
51 class ZeroCopyInputStream; 50 class ZeroCopyInputStream;
52 class ZeroCopyOutputStream; 51 class ZeroCopyOutputStream;
53 } 52 }
54 53
55 // Interface to light weight protocol messages. 54 // Interface to light weight protocol messages.
56 // 55 //
57 // This interface is implemented by all protocol message objects. Non-lite 56 // This interface is implemented by all protocol message objects. Non-lite
(...skipping 24 matching lines...) Expand all
82 81
83 // Basic Operations ------------------------------------------------ 82 // Basic Operations ------------------------------------------------
84 83
85 // Get the name of this message type, e.g. "foo.bar.BazProto". 84 // Get the name of this message type, e.g. "foo.bar.BazProto".
86 virtual string GetTypeName() const = 0; 85 virtual string GetTypeName() const = 0;
87 86
88 // Construct a new instance of the same type. Ownership is passed to the 87 // Construct a new instance of the same type. Ownership is passed to the
89 // caller. 88 // caller.
90 virtual MessageLite* New() const = 0; 89 virtual MessageLite* New() const = 0;
91 90
92 // Construct a new instance on the arena. Ownership is passed to the caller
93 // if arena is a NULL. Default implementation for backwards compatibility.
94 virtual MessageLite* New(::google::protobuf::Arena* arena) const;
95
96 // Get the arena, if any, associated with this message. Virtual method
97 // required for generic operations but most arena-related operations should
98 // use the GetArenaNoVirtual() generated-code method. Default implementation
99 // to reduce code size by avoiding the need for per-type implementations when
100 // types do not implement arena support.
101 virtual ::google::protobuf::Arena* GetArena() const { return NULL; }
102
103 // Get a pointer that may be equal to this message's arena, or may not be. If
104 // the value returned by this method is equal to some arena pointer, then this
105 // message is on that arena; however, if this message is on some arena, this
106 // method may or may not return that arena's pointer. As a tradeoff, this
107 // method may be more efficient than GetArena(). The intent is to allow
108 // underlying representations that use e.g. tagged pointers to sometimes store
109 // the arena pointer directly, and sometimes in a more indirect way, and allow
110 // a fastpath comparison against the arena pointer when it's easy to obtain.
111 virtual void* GetMaybeArenaPointer() const { return GetArena(); }
112
113 // Clear all fields of the message and set them to their default values. 91 // Clear all fields of the message and set them to their default values.
114 // Clear() avoids freeing memory, assuming that any memory allocated 92 // Clear() avoids freeing memory, assuming that any memory allocated
115 // to hold parts of the message will be needed again to hold the next 93 // to hold parts of the message will be needed again to hold the next
116 // message. If you actually want to free the memory used by a Message, 94 // message. If you actually want to free the memory used by a Message,
117 // you must delete it. 95 // you must delete it.
118 virtual void Clear() = 0; 96 virtual void Clear() = 0;
119 97
120 // Quickly check if all required fields have values set. 98 // Quickly check if all required fields have values set.
121 virtual bool IsInitialized() const = 0; 99 virtual bool IsInitialized() const = 0;
122 100
123 // This is not implemented for Lite messages -- it just returns "(cannot 101 // This is not implemented for Lite messages -- it just returns "(cannot
124 // determine missing fields for lite message)". However, it is implemented 102 // determine missing fields for lite message)". However, it is implemented
125 // for full messages. See message.h. 103 // for full messages. See message.h.
126 virtual string InitializationErrorString() const; 104 virtual string InitializationErrorString() const;
127 105
128 // If |other| is the exact same class as this, calls MergeFrom(). Otherwise, 106 // If |other| is the exact same class as this, calls MergeFrom(). Otherwise,
129 // results are undefined (probably crash). 107 // results are undefined (probably crash).
130 virtual void CheckTypeAndMergeFrom(const MessageLite& other) = 0; 108 virtual void CheckTypeAndMergeFrom(const MessageLite& other) = 0;
131 109
132 // Parsing --------------------------------------------------------- 110 // Parsing ---------------------------------------------------------
133 // Methods for parsing in protocol buffer format. Most of these are 111 // Methods for parsing in protocol buffer format. Most of these are
134 // just simple wrappers around MergeFromCodedStream(). Clear() will be called 112 // just simple wrappers around MergeFromCodedStream().
135 // before merging the input.
136 113
137 // Fill the message with a protocol buffer parsed from the given input stream. 114 // Fill the message with a protocol buffer parsed from the given input
138 // Returns false on a read error or if the input is in the wrong format. A 115 // stream. Returns false on a read error or if the input is in the
139 // successful return does not indicate the entire input is consumed, ensure 116 // wrong format.
140 // you call ConsumedEntireMessage() to check that if applicable.
141 bool ParseFromCodedStream(io::CodedInputStream* input); 117 bool ParseFromCodedStream(io::CodedInputStream* input);
142 // Like ParseFromCodedStream(), but accepts messages that are missing 118 // Like ParseFromCodedStream(), but accepts messages that are missing
143 // required fields. 119 // required fields.
144 bool ParsePartialFromCodedStream(io::CodedInputStream* input); 120 bool ParsePartialFromCodedStream(io::CodedInputStream* input);
145 // Read a protocol buffer from the given zero-copy input stream. If 121 // Read a protocol buffer from the given zero-copy input stream. If
146 // successful, the entire input will be consumed. 122 // successful, the entire input will be consumed.
147 bool ParseFromZeroCopyStream(io::ZeroCopyInputStream* input); 123 bool ParseFromZeroCopyStream(io::ZeroCopyInputStream* input);
148 // Like ParseFromZeroCopyStream(), but accepts messages that are missing 124 // Like ParseFromZeroCopyStream(), but accepts messages that are missing
149 // required fields. 125 // required fields.
150 bool ParsePartialFromZeroCopyStream(io::ZeroCopyInputStream* input); 126 bool ParsePartialFromZeroCopyStream(io::ZeroCopyInputStream* input);
151 // Read a protocol buffer from the given zero-copy input stream, expecting 127 // Read a protocol buffer from the given zero-copy input stream, expecting
152 // the message to be exactly "size" bytes long. If successful, exactly 128 // the message to be exactly "size" bytes long. If successful, exactly
153 // this many bytes will have been consumed from the input. 129 // this many bytes will have been consumed from the input.
154 bool ParseFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, int size); 130 bool ParseFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, int size);
155 // Like ParseFromBoundedZeroCopyStream(), but accepts messages that are 131 // Like ParseFromBoundedZeroCopyStream(), but accepts messages that are
156 // missing required fields. 132 // missing required fields.
157 bool ParsePartialFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, 133 bool ParsePartialFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input,
158 int size); 134 int size);
159 // Parses a protocol buffer contained in a string. Returns true on success. 135 // Parse a protocol buffer contained in a string.
160 // This function takes a string in the (non-human-readable) binary wire
161 // format, matching the encoding output by MessageLite::SerializeToString().
162 // If you'd like to convert a human-readable string into a protocol buffer
163 // object, see google::protobuf::TextFormat::ParseFromString().
164 bool ParseFromString(const string& data); 136 bool ParseFromString(const string& data);
165 // Like ParseFromString(), but accepts messages that are missing 137 // Like ParseFromString(), but accepts messages that are missing
166 // required fields. 138 // required fields.
167 bool ParsePartialFromString(const string& data); 139 bool ParsePartialFromString(const string& data);
168 // Parse a protocol buffer contained in an array of bytes. 140 // Parse a protocol buffer contained in an array of bytes.
169 bool ParseFromArray(const void* data, int size); 141 bool ParseFromArray(const void* data, int size);
170 // Like ParseFromArray(), but accepts messages that are missing 142 // Like ParseFromArray(), but accepts messages that are missing
171 // required fields. 143 // required fields.
172 bool ParsePartialFromArray(const void* data, int size); 144 bool ParsePartialFromArray(const void* data, int size);
173 145
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 203
232 // Like SerializeToString(), but appends to the data to the string's existing 204 // Like SerializeToString(), but appends to the data to the string's existing
233 // contents. All required fields must be set. 205 // contents. All required fields must be set.
234 bool AppendToString(string* output) const; 206 bool AppendToString(string* output) const;
235 // Like AppendToString(), but allows missing required fields. 207 // Like AppendToString(), but allows missing required fields.
236 bool AppendPartialToString(string* output) const; 208 bool AppendPartialToString(string* output) const;
237 209
238 // Computes the serialized size of the message. This recursively calls 210 // Computes the serialized size of the message. This recursively calls
239 // ByteSize() on all embedded messages. If a subclass does not override 211 // ByteSize() on all embedded messages. If a subclass does not override
240 // this, it MUST override SetCachedSize(). 212 // this, it MUST override SetCachedSize().
241 //
242 // ByteSize() is generally linear in the number of fields defined for the
243 // proto.
244 virtual int ByteSize() const = 0; 213 virtual int ByteSize() const = 0;
245 214
246 // Serializes the message without recomputing the size. The message must 215 // Serializes the message without recomputing the size. The message must
247 // not have changed since the last call to ByteSize(); if it has, the results 216 // not have changed since the last call to ByteSize(); if it has, the results
248 // are undefined. 217 // are undefined.
249 virtual void SerializeWithCachedSizes( 218 virtual void SerializeWithCachedSizes(
250 io::CodedOutputStream* output) const = 0; 219 io::CodedOutputStream* output) const = 0;
251 220
252 // Like SerializeWithCachedSizes, but writes directly to *target, returning 221 // Like SerializeWithCachedSizes, but writes directly to *target, returning
253 // a pointer to the byte immediately after the last byte written. "target" 222 // a pointer to the byte immediately after the last byte written. "target"
(...skipping 14 matching lines...) Expand all
268 virtual int GetCachedSize() const = 0; 237 virtual int GetCachedSize() const = 0;
269 238
270 private: 239 private:
271 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageLite); 240 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageLite);
272 }; 241 };
273 242
274 } // namespace protobuf 243 } // namespace protobuf
275 244
276 } // namespace google 245 } // namespace google
277 #endif // GOOGLE_PROTOBUF_MESSAGE_LITE_H__ 246 #endif // GOOGLE_PROTOBUF_MESSAGE_LITE_H__
OLDNEW
« no previous file with comments | « third_party/protobuf/src/google/protobuf/message.cc ('k') | third_party/protobuf/src/google/protobuf/message_lite.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698