| OLD | NEW |
| 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 // http://code.google.com/p/protobuf/ | 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. |
| 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 Loading... |
| 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 |
| 44 namespace google { | 45 namespace google { |
| 45 namespace protobuf { | 46 namespace protobuf { |
| 46 | 47 class Arena; |
| 47 namespace io { | 48 namespace io { |
| 48 class CodedInputStream; | 49 class CodedInputStream; |
| 49 class CodedOutputStream; | 50 class CodedOutputStream; |
| 50 class ZeroCopyInputStream; | 51 class ZeroCopyInputStream; |
| 51 class ZeroCopyOutputStream; | 52 class ZeroCopyOutputStream; |
| 52 } | 53 } |
| 53 | 54 |
| 54 // Interface to light weight protocol messages. | 55 // Interface to light weight protocol messages. |
| 55 // | 56 // |
| 56 // This interface is implemented by all protocol message objects. Non-lite | 57 // This interface is implemented by all protocol message objects. Non-lite |
| (...skipping 24 matching lines...) Expand all Loading... |
| 81 | 82 |
| 82 // Basic Operations ------------------------------------------------ | 83 // Basic Operations ------------------------------------------------ |
| 83 | 84 |
| 84 // Get the name of this message type, e.g. "foo.bar.BazProto". | 85 // Get the name of this message type, e.g. "foo.bar.BazProto". |
| 85 virtual string GetTypeName() const = 0; | 86 virtual string GetTypeName() const = 0; |
| 86 | 87 |
| 87 // Construct a new instance of the same type. Ownership is passed to the | 88 // Construct a new instance of the same type. Ownership is passed to the |
| 88 // caller. | 89 // caller. |
| 89 virtual MessageLite* New() const = 0; | 90 virtual MessageLite* New() const = 0; |
| 90 | 91 |
| 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 |
| 91 // Clear all fields of the message and set them to their default values. | 113 // Clear all fields of the message and set them to their default values. |
| 92 // Clear() avoids freeing memory, assuming that any memory allocated | 114 // Clear() avoids freeing memory, assuming that any memory allocated |
| 93 // to hold parts of the message will be needed again to hold the next | 115 // to hold parts of the message will be needed again to hold the next |
| 94 // message. If you actually want to free the memory used by a Message, | 116 // message. If you actually want to free the memory used by a Message, |
| 95 // you must delete it. | 117 // you must delete it. |
| 96 virtual void Clear() = 0; | 118 virtual void Clear() = 0; |
| 97 | 119 |
| 98 // Quickly check if all required fields have values set. | 120 // Quickly check if all required fields have values set. |
| 99 virtual bool IsInitialized() const = 0; | 121 virtual bool IsInitialized() const = 0; |
| 100 | 122 |
| 101 // This is not implemented for Lite messages -- it just returns "(cannot | 123 // This is not implemented for Lite messages -- it just returns "(cannot |
| 102 // determine missing fields for lite message)". However, it is implemented | 124 // determine missing fields for lite message)". However, it is implemented |
| 103 // for full messages. See message.h. | 125 // for full messages. See message.h. |
| 104 virtual string InitializationErrorString() const; | 126 virtual string InitializationErrorString() const; |
| 105 | 127 |
| 106 // If |other| is the exact same class as this, calls MergeFrom(). Otherwise, | 128 // If |other| is the exact same class as this, calls MergeFrom(). Otherwise, |
| 107 // results are undefined (probably crash). | 129 // results are undefined (probably crash). |
| 108 virtual void CheckTypeAndMergeFrom(const MessageLite& other) = 0; | 130 virtual void CheckTypeAndMergeFrom(const MessageLite& other) = 0; |
| 109 | 131 |
| 110 // Parsing --------------------------------------------------------- | 132 // Parsing --------------------------------------------------------- |
| 111 // Methods for parsing in protocol buffer format. Most of these are | 133 // Methods for parsing in protocol buffer format. Most of these are |
| 112 // just simple wrappers around MergeFromCodedStream(). | 134 // just simple wrappers around MergeFromCodedStream(). Clear() will be called |
| 135 // before merging the input. |
| 113 | 136 |
| 114 // Fill the message with a protocol buffer parsed from the given input | 137 // Fill the message with a protocol buffer parsed from the given input stream. |
| 115 // stream. Returns false on a read error or if the input is in the | 138 // Returns false on a read error or if the input is in the wrong format. A |
| 116 // wrong format. | 139 // successful return does not indicate the entire input is consumed, ensure |
| 140 // you call ConsumedEntireMessage() to check that if applicable. |
| 117 bool ParseFromCodedStream(io::CodedInputStream* input); | 141 bool ParseFromCodedStream(io::CodedInputStream* input); |
| 118 // Like ParseFromCodedStream(), but accepts messages that are missing | 142 // Like ParseFromCodedStream(), but accepts messages that are missing |
| 119 // required fields. | 143 // required fields. |
| 120 bool ParsePartialFromCodedStream(io::CodedInputStream* input); | 144 bool ParsePartialFromCodedStream(io::CodedInputStream* input); |
| 121 // Read a protocol buffer from the given zero-copy input stream. If | 145 // Read a protocol buffer from the given zero-copy input stream. If |
| 122 // successful, the entire input will be consumed. | 146 // successful, the entire input will be consumed. |
| 123 bool ParseFromZeroCopyStream(io::ZeroCopyInputStream* input); | 147 bool ParseFromZeroCopyStream(io::ZeroCopyInputStream* input); |
| 124 // Like ParseFromZeroCopyStream(), but accepts messages that are missing | 148 // Like ParseFromZeroCopyStream(), but accepts messages that are missing |
| 125 // required fields. | 149 // required fields. |
| 126 bool ParsePartialFromZeroCopyStream(io::ZeroCopyInputStream* input); | 150 bool ParsePartialFromZeroCopyStream(io::ZeroCopyInputStream* input); |
| 127 // Read a protocol buffer from the given zero-copy input stream, expecting | 151 // Read a protocol buffer from the given zero-copy input stream, expecting |
| 128 // the message to be exactly "size" bytes long. If successful, exactly | 152 // the message to be exactly "size" bytes long. If successful, exactly |
| 129 // this many bytes will have been consumed from the input. | 153 // this many bytes will have been consumed from the input. |
| 130 bool ParseFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, int size); | 154 bool ParseFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, int size); |
| 131 // Like ParseFromBoundedZeroCopyStream(), but accepts messages that are | 155 // Like ParseFromBoundedZeroCopyStream(), but accepts messages that are |
| 132 // missing required fields. | 156 // missing required fields. |
| 133 bool ParsePartialFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, | 157 bool ParsePartialFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, |
| 134 int size); | 158 int size); |
| 135 // Parse a protocol buffer contained in a string. | 159 // Parses a protocol buffer contained in a string. Returns true on success. |
| 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(). |
| 136 bool ParseFromString(const string& data); | 164 bool ParseFromString(const string& data); |
| 137 // Like ParseFromString(), but accepts messages that are missing | 165 // Like ParseFromString(), but accepts messages that are missing |
| 138 // required fields. | 166 // required fields. |
| 139 bool ParsePartialFromString(const string& data); | 167 bool ParsePartialFromString(const string& data); |
| 140 // Parse a protocol buffer contained in an array of bytes. | 168 // Parse a protocol buffer contained in an array of bytes. |
| 141 bool ParseFromArray(const void* data, int size); | 169 bool ParseFromArray(const void* data, int size); |
| 142 // Like ParseFromArray(), but accepts messages that are missing | 170 // Like ParseFromArray(), but accepts messages that are missing |
| 143 // required fields. | 171 // required fields. |
| 144 bool ParsePartialFromArray(const void* data, int size); | 172 bool ParsePartialFromArray(const void* data, int size); |
| 145 | 173 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 231 |
| 204 // Like SerializeToString(), but appends to the data to the string's existing | 232 // Like SerializeToString(), but appends to the data to the string's existing |
| 205 // contents. All required fields must be set. | 233 // contents. All required fields must be set. |
| 206 bool AppendToString(string* output) const; | 234 bool AppendToString(string* output) const; |
| 207 // Like AppendToString(), but allows missing required fields. | 235 // Like AppendToString(), but allows missing required fields. |
| 208 bool AppendPartialToString(string* output) const; | 236 bool AppendPartialToString(string* output) const; |
| 209 | 237 |
| 210 // Computes the serialized size of the message. This recursively calls | 238 // Computes the serialized size of the message. This recursively calls |
| 211 // ByteSize() on all embedded messages. If a subclass does not override | 239 // ByteSize() on all embedded messages. If a subclass does not override |
| 212 // this, it MUST override SetCachedSize(). | 240 // this, it MUST override SetCachedSize(). |
| 241 // |
| 242 // ByteSize() is generally linear in the number of fields defined for the |
| 243 // proto. |
| 213 virtual int ByteSize() const = 0; | 244 virtual int ByteSize() const = 0; |
| 214 | 245 |
| 215 // Serializes the message without recomputing the size. The message must | 246 // Serializes the message without recomputing the size. The message must |
| 216 // not have changed since the last call to ByteSize(); if it has, the results | 247 // not have changed since the last call to ByteSize(); if it has, the results |
| 217 // are undefined. | 248 // are undefined. |
| 218 virtual void SerializeWithCachedSizes( | 249 virtual void SerializeWithCachedSizes( |
| 219 io::CodedOutputStream* output) const = 0; | 250 io::CodedOutputStream* output) const = 0; |
| 220 | 251 |
| 221 // Like SerializeWithCachedSizes, but writes directly to *target, returning | 252 // Like SerializeWithCachedSizes, but writes directly to *target, returning |
| 222 // a pointer to the byte immediately after the last byte written. "target" | 253 // a pointer to the byte immediately after the last byte written. "target" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 237 virtual int GetCachedSize() const = 0; | 268 virtual int GetCachedSize() const = 0; |
| 238 | 269 |
| 239 private: | 270 private: |
| 240 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageLite); | 271 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageLite); |
| 241 }; | 272 }; |
| 242 | 273 |
| 243 } // namespace protobuf | 274 } // namespace protobuf |
| 244 | 275 |
| 245 } // namespace google | 276 } // namespace google |
| 246 #endif // GOOGLE_PROTOBUF_MESSAGE_LITE_H__ | 277 #endif // GOOGLE_PROTOBUF_MESSAGE_LITE_H__ |
| OLD | NEW |