OsmAnd
|
00001 // Protocol Buffers - Google's data interchange format 00002 // Copyright 2008 Google Inc. All rights reserved. 00003 // http://code.google.com/p/protobuf/ 00004 // 00005 // Redistribution and use in source and binary forms, with or without 00006 // modification, are permitted provided that the following conditions are 00007 // met: 00008 // 00009 // * Redistributions of source code must retain the above copyright 00010 // notice, this list of conditions and the following disclaimer. 00011 // * Redistributions in binary form must reproduce the above 00012 // copyright notice, this list of conditions and the following disclaimer 00013 // in the documentation and/or other materials provided with the 00014 // distribution. 00015 // * Neither the name of Google Inc. nor the names of its 00016 // contributors may be used to endorse or promote products derived from 00017 // this software without specific prior written permission. 00018 // 00019 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00022 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00023 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00024 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00025 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00026 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00027 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00029 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 00031 // Author: kenton@google.com (Kenton Varda) 00032 // Based on original Protocol Buffers design by 00033 // Sanjay Ghemawat, Jeff Dean, and others. 00034 // 00035 // This file contains the CodedInputStream and CodedOutputStream classes, 00036 // which wrap a ZeroCopyInputStream or ZeroCopyOutputStream, respectively, 00037 // and allow you to read or write individual pieces of data in various 00038 // formats. In particular, these implement the varint encoding for 00039 // integers, a simple variable-length encoding in which smaller numbers 00040 // take fewer bytes. 00041 // 00042 // Typically these classes will only be used internally by the protocol 00043 // buffer library in order to encode and decode protocol buffers. Clients 00044 // of the library only need to know about this class if they wish to write 00045 // custom message parsing or serialization procedures. 00046 // 00047 // CodedOutputStream example: 00048 // // Write some data to "myfile". First we write a 4-byte "magic number" 00049 // // to identify the file type, then write a length-delimited string. The 00050 // // string is composed of a varint giving the length followed by the raw 00051 // // bytes. 00052 // int fd = open("myfile", O_WRONLY); 00053 // ZeroCopyOutputStream* raw_output = new FileOutputStream(fd); 00054 // CodedOutputStream* coded_output = new CodedOutputStream(raw_output); 00055 // 00056 // int magic_number = 1234; 00057 // char text[] = "Hello world!"; 00058 // coded_output->WriteLittleEndian32(magic_number); 00059 // coded_output->WriteVarint32(strlen(text)); 00060 // coded_output->WriteRaw(text, strlen(text)); 00061 // 00062 // delete coded_output; 00063 // delete raw_output; 00064 // close(fd); 00065 // 00066 // CodedInputStream example: 00067 // // Read a file created by the above code. 00068 // int fd = open("myfile", O_RDONLY); 00069 // ZeroCopyInputStream* raw_input = new FileInputStream(fd); 00070 // CodedInputStream coded_input = new CodedInputStream(raw_input); 00071 // 00072 // coded_input->ReadLittleEndian32(&magic_number); 00073 // if (magic_number != 1234) { 00074 // cerr << "File not in expected format." << endl; 00075 // return; 00076 // } 00077 // 00078 // uint32 size; 00079 // coded_input->ReadVarint32(&size); 00080 // 00081 // char* text = new char[size + 1]; 00082 // coded_input->ReadRaw(buffer, size); 00083 // text[size] = '\0'; 00084 // 00085 // delete coded_input; 00086 // delete raw_input; 00087 // close(fd); 00088 // 00089 // cout << "Text is: " << text << endl; 00090 // delete [] text; 00091 // 00092 // For those who are interested, varint encoding is defined as follows: 00093 // 00094 // The encoding operates on unsigned integers of up to 64 bits in length. 00095 // Each byte of the encoded value has the format: 00096 // * bits 0-6: Seven bits of the number being encoded. 00097 // * bit 7: Zero if this is the last byte in the encoding (in which 00098 // case all remaining bits of the number are zero) or 1 if 00099 // more bytes follow. 00100 // The first byte contains the least-significant 7 bits of the number, the 00101 // second byte (if present) contains the next-least-significant 7 bits, 00102 // and so on. So, the binary number 1011000101011 would be encoded in two 00103 // bytes as "10101011 00101100". 00104 // 00105 // In theory, varint could be used to encode integers of any length. 00106 // However, for practicality we set a limit at 64 bits. The maximum encoded 00107 // length of a number is thus 10 bytes. 00108 00109 #ifndef GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ 00110 #define GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ 00111 00112 #include <string> 00113 #ifndef _MSC_VER 00114 #include <sys/param.h> 00115 #endif // !_MSC_VER 00116 #include <google/protobuf/stubs/common.h> 00117 #include <google/protobuf/stubs/common.h> // for GOOGLE_PREDICT_TRUE macro 00118 00119 namespace google { 00120 00121 namespace protobuf { 00122 00123 class DescriptorPool; 00124 class MessageFactory; 00125 00126 namespace io { 00127 00128 // Defined in this file. 00129 class CodedInputStream; 00130 class CodedOutputStream; 00131 00132 // Defined in other files. 00133 class ZeroCopyInputStream; // zero_copy_stream.h 00134 class ZeroCopyOutputStream; // zero_copy_stream.h 00135 00136 // Class which reads and decodes binary data which is composed of varint- 00137 // encoded integers and fixed-width pieces. Wraps a ZeroCopyInputStream. 00138 // Most users will not need to deal with CodedInputStream. 00139 // 00140 // Most methods of CodedInputStream that return a bool return false if an 00141 // underlying I/O error occurs or if the data is malformed. Once such a 00142 // failure occurs, the CodedInputStream is broken and is no longer useful. 00143 class LIBPROTOBUF_EXPORT CodedInputStream { 00144 public: 00145 // Create a CodedInputStream that reads from the given ZeroCopyInputStream. 00146 explicit CodedInputStream(ZeroCopyInputStream* input); 00147 00148 // Create a CodedInputStream that reads from the given flat array. This is 00149 // faster than using an ArrayInputStream. PushLimit(size) is implied by 00150 // this constructor. 00151 explicit CodedInputStream(const uint8* buffer, int size); 00152 00153 // Destroy the CodedInputStream and position the underlying 00154 // ZeroCopyInputStream at the first unread byte. If an error occurred while 00155 // reading (causing a method to return false), then the exact position of 00156 // the input stream may be anywhere between the last value that was read 00157 // successfully and the stream's byte limit. 00158 ~CodedInputStream(); 00159 00160 00161 // Skips a number of bytes. Returns false if an underlying read error 00162 // occurs. 00163 bool Skip(int count); 00164 00165 // Osmand change : Seeks in the file 00166 bool Seek(int filePointer); 00167 00168 // Sets *data to point directly at the unread part of the CodedInputStream's 00169 // underlying buffer, and *size to the size of that buffer, but does not 00170 // advance the stream's current position. This will always either produce 00171 // a non-empty buffer or return false. If the caller consumes any of 00172 // this data, it should then call Skip() to skip over the consumed bytes. 00173 // This may be useful for implementing external fast parsing routines for 00174 // types of data not covered by the CodedInputStream interface. 00175 bool GetDirectBufferPointer(const void** data, int* size); 00176 00177 // Like GetDirectBufferPointer, but this method is inlined, and does not 00178 // attempt to Refresh() if the buffer is currently empty. 00179 inline void GetDirectBufferPointerInline(const void** data, 00180 int* size) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; 00181 00182 // Read raw bytes, copying them into the given buffer. 00183 bool ReadRaw(void* buffer, int size); 00184 00185 // Like ReadRaw, but reads into a string. 00186 // 00187 // Implementation Note: ReadString() grows the string gradually as it 00188 // reads in the data, rather than allocating the entire requested size 00189 // upfront. This prevents denial-of-service attacks in which a client 00190 // could claim that a string is going to be MAX_INT bytes long in order to 00191 // crash the server because it can't allocate this much space at once. 00192 bool ReadString(string* buffer, int size); 00193 // Like the above, with inlined optimizations. This should only be used 00194 // by the protobuf implementation. 00195 inline bool InternalReadStringInline(string* buffer, 00196 int size) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; 00197 00198 00199 // Read a 32-bit little-endian integer. 00200 bool ReadLittleEndian32(uint32* value); 00201 // Read a 64-bit little-endian integer. 00202 bool ReadLittleEndian64(uint64* value); 00203 00204 // These methods read from an externally provided buffer. The caller is 00205 // responsible for ensuring that the buffer has sufficient space. 00206 // Read a 32-bit little-endian integer. 00207 static const uint8* ReadLittleEndian32FromArray(const uint8* buffer, 00208 uint32* value); 00209 // Read a 64-bit little-endian integer. 00210 static const uint8* ReadLittleEndian64FromArray(const uint8* buffer, 00211 uint64* value); 00212 00213 // Read an unsigned integer with Varint encoding, truncating to 32 bits. 00214 // Reading a 32-bit value is equivalent to reading a 64-bit one and casting 00215 // it to uint32, but may be more efficient. 00216 bool ReadVarint32(uint32* value); 00217 // Read an unsigned integer with Varint encoding. 00218 bool ReadVarint64(uint64* value); 00219 00220 // Read a tag. This calls ReadVarint32() and returns the result, or returns 00221 // zero (which is not a valid tag) if ReadVarint32() fails. Also, it updates 00222 // the last tag value, which can be checked with LastTagWas(). 00223 // Always inline because this is only called in once place per parse loop 00224 // but it is called for every iteration of said loop, so it should be fast. 00225 // GCC doesn't want to inline this by default. 00226 uint32 ReadTag() GOOGLE_ATTRIBUTE_ALWAYS_INLINE; 00227 00228 // Usually returns true if calling ReadVarint32() now would produce the given 00229 // value. Will always return false if ReadVarint32() would not return the 00230 // given value. If ExpectTag() returns true, it also advances past 00231 // the varint. For best performance, use a compile-time constant as the 00232 // parameter. 00233 // Always inline because this collapses to a small number of instructions 00234 // when given a constant parameter, but GCC doesn't want to inline by default. 00235 bool ExpectTag(uint32 expected) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; 00236 00237 // Like above, except this reads from the specified buffer. The caller is 00238 // responsible for ensuring that the buffer is large enough to read a varint 00239 // of the expected size. For best performance, use a compile-time constant as 00240 // the expected tag parameter. 00241 // 00242 // Returns a pointer beyond the expected tag if it was found, or NULL if it 00243 // was not. 00244 static const uint8* ExpectTagFromArray( 00245 const uint8* buffer, 00246 uint32 expected) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; 00247 00248 // Usually returns true if no more bytes can be read. Always returns false 00249 // if more bytes can be read. If ExpectAtEnd() returns true, a subsequent 00250 // call to LastTagWas() will act as if ReadTag() had been called and returned 00251 // zero, and ConsumedEntireMessage() will return true. 00252 bool ExpectAtEnd(); 00253 00254 // If the last call to ReadTag() returned the given value, returns true. 00255 // Otherwise, returns false; 00256 // 00257 // This is needed because parsers for some types of embedded messages 00258 // (with field type TYPE_GROUP) don't actually know that they've reached the 00259 // end of a message until they see an ENDGROUP tag, which was actually part 00260 // of the enclosing message. The enclosing message would like to check that 00261 // tag to make sure it had the right number, so it calls LastTagWas() on 00262 // return from the embedded parser to check. 00263 bool LastTagWas(uint32 expected); 00264 00265 // When parsing message (but NOT a group), this method must be called 00266 // immediately after MergeFromCodedStream() returns (if it returns true) 00267 // to further verify that the message ended in a legitimate way. For 00268 // example, this verifies that parsing did not end on an end-group tag. 00269 // It also checks for some cases where, due to optimizations, 00270 // MergeFromCodedStream() can incorrectly return true. 00271 bool ConsumedEntireMessage(); 00272 00273 // Limits ---------------------------------------------------------- 00274 // Limits are used when parsing length-delimited embedded messages. 00275 // After the message's length is read, PushLimit() is used to prevent 00276 // the CodedInputStream from reading beyond that length. Once the 00277 // embedded message has been parsed, PopLimit() is called to undo the 00278 // limit. 00279 00280 // Opaque type used with PushLimit() and PopLimit(). Do not modify 00281 // values of this type yourself. The only reason that this isn't a 00282 // struct with private internals is for efficiency. 00283 typedef int Limit; 00284 00285 // Places a limit on the number of bytes that the stream may read, 00286 // starting from the current position. Once the stream hits this limit, 00287 // it will act like the end of the input has been reached until PopLimit() 00288 // is called. 00289 // 00290 // As the names imply, the stream conceptually has a stack of limits. The 00291 // shortest limit on the stack is always enforced, even if it is not the 00292 // top limit. 00293 // 00294 // The value returned by PushLimit() is opaque to the caller, and must 00295 // be passed unchanged to the corresponding call to PopLimit(). 00296 Limit PushLimit(int byte_limit); 00297 00298 // Pops the last limit pushed by PushLimit(). The input must be the value 00299 // returned by that call to PushLimit(). 00300 void PopLimit(Limit limit); 00301 00302 // Returns the number of bytes left until the nearest limit on the 00303 // stack is hit, or -1 if no limits are in place. 00304 int BytesUntilLimit(); 00305 00306 // osmand change : totally bytes read 00307 int getTotalBytesRead(); 00308 00309 // Total Bytes Limit ----------------------------------------------- 00310 // To prevent malicious users from sending excessively large messages 00311 // and causing integer overflows or memory exhaustion, CodedInputStream 00312 // imposes a hard limit on the total number of bytes it will read. 00313 00314 // Sets the maximum number of bytes that this CodedInputStream will read 00315 // before refusing to continue. To prevent integer overflows in the 00316 // protocol buffers implementation, as well as to prevent servers from 00317 // allocating enormous amounts of memory to hold parsed messages, the 00318 // maximum message length should be limited to the shortest length that 00319 // will not harm usability. The theoretical shortest message that could 00320 // cause integer overflows is 512MB. The default limit is 64MB. Apps 00321 // should set shorter limits if possible. If warning_threshold is not -1, 00322 // a warning will be printed to stderr after warning_threshold bytes are 00323 // read. An error will always be printed to stderr if the limit is 00324 // reached. 00325 // 00326 // This is unrelated to PushLimit()/PopLimit(). 00327 // 00328 // Hint: If you are reading this because your program is printing a 00329 // warning about dangerously large protocol messages, you may be 00330 // confused about what to do next. The best option is to change your 00331 // design such that excessively large messages are not necessary. 00332 // For example, try to design file formats to consist of many small 00333 // messages rather than a single large one. If this is infeasible, 00334 // you will need to increase the limit. Chances are, though, that 00335 // your code never constructs a CodedInputStream on which the limit 00336 // can be set. You probably parse messages by calling things like 00337 // Message::ParseFromString(). In this case, you will need to change 00338 // your code to instead construct some sort of ZeroCopyInputStream 00339 // (e.g. an ArrayInputStream), construct a CodedInputStream around 00340 // that, then call Message::ParseFromCodedStream() instead. Then 00341 // you can adjust the limit. Yes, it's more work, but you're doing 00342 // something unusual. 00343 void SetTotalBytesLimit(int total_bytes_limit, int warning_threshold); 00344 00345 // Recursion Limit ------------------------------------------------- 00346 // To prevent corrupt or malicious messages from causing stack overflows, 00347 // we must keep track of the depth of recursion when parsing embedded 00348 // messages and groups. CodedInputStream keeps track of this because it 00349 // is the only object that is passed down the stack during parsing. 00350 00351 // Sets the maximum recursion depth. The default is 64. 00352 void SetRecursionLimit(int limit); 00353 00354 // Increments the current recursion depth. Returns true if the depth is 00355 // under the limit, false if it has gone over. 00356 bool IncrementRecursionDepth(); 00357 00358 // Decrements the recursion depth. 00359 void DecrementRecursionDepth(); 00360 00361 // Extension Registry ---------------------------------------------- 00362 // ADVANCED USAGE: 99.9% of people can ignore this section. 00363 // 00364 // By default, when parsing extensions, the parser looks for extension 00365 // definitions in the pool which owns the outer message's Descriptor. 00366 // However, you may call SetExtensionRegistry() to provide an alternative 00367 // pool instead. This makes it possible, for example, to parse a message 00368 // using a generated class, but represent some extensions using 00369 // DynamicMessage. 00370 00371 // Set the pool used to look up extensions. Most users do not need to call 00372 // this as the correct pool will be chosen automatically. 00373 // 00374 // WARNING: It is very easy to misuse this. Carefully read the requirements 00375 // below. Do not use this unless you are sure you need it. Almost no one 00376 // does. 00377 // 00378 // Let's say you are parsing a message into message object m, and you want 00379 // to take advantage of SetExtensionRegistry(). You must follow these 00380 // requirements: 00381 // 00382 // The given DescriptorPool must contain m->GetDescriptor(). It is not 00383 // sufficient for it to simply contain a descriptor that has the same name 00384 // and content -- it must be the *exact object*. In other words: 00385 // assert(pool->FindMessageTypeByName(m->GetDescriptor()->full_name()) == 00386 // m->GetDescriptor()); 00387 // There are two ways to satisfy this requirement: 00388 // 1) Use m->GetDescriptor()->pool() as the pool. This is generally useless 00389 // because this is the pool that would be used anyway if you didn't call 00390 // SetExtensionRegistry() at all. 00391 // 2) Use a DescriptorPool which has m->GetDescriptor()->pool() as an 00392 // "underlay". Read the documentation for DescriptorPool for more 00393 // information about underlays. 00394 // 00395 // You must also provide a MessageFactory. This factory will be used to 00396 // construct Message objects representing extensions. The factory's 00397 // GetPrototype() MUST return non-NULL for any Descriptor which can be found 00398 // through the provided pool. 00399 // 00400 // If the provided factory might return instances of protocol-compiler- 00401 // generated (i.e. compiled-in) types, or if the outer message object m is 00402 // a generated type, then the given factory MUST have this property: If 00403 // GetPrototype() is given a Descriptor which resides in 00404 // DescriptorPool::generated_pool(), the factory MUST return the same 00405 // prototype which MessageFactory::generated_factory() would return. That 00406 // is, given a descriptor for a generated type, the factory must return an 00407 // instance of the generated class (NOT DynamicMessage). However, when 00408 // given a descriptor for a type that is NOT in generated_pool, the factory 00409 // is free to return any implementation. 00410 // 00411 // The reason for this requirement is that generated sub-objects may be 00412 // accessed via the standard (non-reflection) extension accessor methods, 00413 // and these methods will down-cast the object to the generated class type. 00414 // If the object is not actually of that type, the results would be undefined. 00415 // On the other hand, if an extension is not compiled in, then there is no 00416 // way the code could end up accessing it via the standard accessors -- the 00417 // only way to access the extension is via reflection. When using reflection, 00418 // DynamicMessage and generated messages are indistinguishable, so it's fine 00419 // if these objects are represented using DynamicMessage. 00420 // 00421 // Using DynamicMessageFactory on which you have called 00422 // SetDelegateToGeneratedFactory(true) should be sufficient to satisfy the 00423 // above requirement. 00424 // 00425 // If either pool or factory is NULL, both must be NULL. 00426 // 00427 // Note that this feature is ignored when parsing "lite" messages as they do 00428 // not have descriptors. 00429 void SetExtensionRegistry(DescriptorPool* pool, MessageFactory* factory); 00430 00431 // Get the DescriptorPool set via SetExtensionRegistry(), or NULL if no pool 00432 // has been provided. 00433 const DescriptorPool* GetExtensionPool(); 00434 00435 // Get the MessageFactory set via SetExtensionRegistry(), or NULL if no 00436 // factory has been provided. 00437 MessageFactory* GetExtensionFactory(); 00438 00439 private: 00440 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedInputStream); 00441 00442 ZeroCopyInputStream* input_; 00443 const uint8* buffer_; 00444 const uint8* buffer_end_; // pointer to the end of the buffer. 00445 int total_bytes_read_; // total bytes read from input_, including 00446 // the current buffer 00447 00448 // If total_bytes_read_ surpasses INT_MAX, we record the extra bytes here 00449 // so that we can BackUp() on destruction. 00450 int overflow_bytes_; 00451 00452 // LastTagWas() stuff. 00453 uint32 last_tag_; // result of last ReadTag(). 00454 00455 // This is set true by ReadTag{Fallback/Slow}() if it is called when exactly 00456 // at EOF, or by ExpectAtEnd() when it returns true. This happens when we 00457 // reach the end of a message and attempt to read another tag. 00458 bool legitimate_message_end_; 00459 00460 // See EnableAliasing(). 00461 bool aliasing_enabled_; 00462 00463 // Limits 00464 Limit current_limit_; // if position = -1, no limit is applied 00465 00466 // For simplicity, if the current buffer crosses a limit (either a normal 00467 // limit created by PushLimit() or the total bytes limit), buffer_size_ 00468 // only tracks the number of bytes before that limit. This field 00469 // contains the number of bytes after it. Note that this implies that if 00470 // buffer_size_ == 0 and buffer_size_after_limit_ > 0, we know we've 00471 // hit a limit. However, if both are zero, it doesn't necessarily mean 00472 // we aren't at a limit -- the buffer may have ended exactly at the limit. 00473 int buffer_size_after_limit_; 00474 00475 // Maximum number of bytes to read, period. This is unrelated to 00476 // current_limit_. Set using SetTotalBytesLimit(). 00477 int total_bytes_limit_; 00478 int total_bytes_warning_threshold_; 00479 00480 // Current recursion depth, controlled by IncrementRecursionDepth() and 00481 // DecrementRecursionDepth(). 00482 int recursion_depth_; 00483 // Recursion depth limit, set by SetRecursionLimit(). 00484 int recursion_limit_; 00485 00486 // See SetExtensionRegistry(). 00487 const DescriptorPool* extension_pool_; 00488 MessageFactory* extension_factory_; 00489 00490 // Private member functions. 00491 00492 // Advance the buffer by a given number of bytes. 00493 void Advance(int amount); 00494 00495 // Back up input_ to the current buffer position. 00496 void BackUpInputToCurrentPosition(); 00497 00498 // Recomputes the value of buffer_size_after_limit_. Must be called after 00499 // current_limit_ or total_bytes_limit_ changes. 00500 void RecomputeBufferLimits(); 00501 00502 // Writes an error message saying that we hit total_bytes_limit_. 00503 void PrintTotalBytesLimitError(); 00504 00505 // Called when the buffer runs out to request more data. Implies an 00506 // Advance(BufferSize()). 00507 bool Refresh(); 00508 00509 // When parsing varints, we optimize for the common case of small values, and 00510 // then optimize for the case when the varint fits within the current buffer 00511 // piece. The Fallback method is used when we can't use the one-byte 00512 // optimization. The Slow method is yet another fallback when the buffer is 00513 // not large enough. Making the slow path out-of-line speeds up the common 00514 // case by 10-15%. The slow path is fairly uncommon: it only triggers when a 00515 // message crosses multiple buffers. 00516 bool ReadVarint32Fallback(uint32* value); 00517 bool ReadVarint64Fallback(uint64* value); 00518 bool ReadVarint32Slow(uint32* value); 00519 bool ReadVarint64Slow(uint64* value); 00520 bool ReadLittleEndian32Fallback(uint32* value); 00521 bool ReadLittleEndian64Fallback(uint64* value); 00522 // Fallback/slow methods for reading tags. These do not update last_tag_, 00523 // but will set legitimate_message_end_ if we are at the end of the input 00524 // stream. 00525 uint32 ReadTagFallback(); 00526 uint32 ReadTagSlow(); 00527 bool ReadStringFallback(string* buffer, int size); 00528 00529 // Return the size of the buffer. 00530 int BufferSize() const; 00531 00532 static const int kDefaultTotalBytesLimit = 64 << 20; // 64MB 00533 00534 static const int kDefaultTotalBytesWarningThreshold = 32 << 20; // 32MB 00535 static const int kDefaultRecursionLimit = 64; 00536 }; 00537 00538 // Class which encodes and writes binary data which is composed of varint- 00539 // encoded integers and fixed-width pieces. Wraps a ZeroCopyOutputStream. 00540 // Most users will not need to deal with CodedOutputStream. 00541 // 00542 // Most methods of CodedOutputStream which return a bool return false if an 00543 // underlying I/O error occurs. Once such a failure occurs, the 00544 // CodedOutputStream is broken and is no longer useful. The Write* methods do 00545 // not return the stream status, but will invalidate the stream if an error 00546 // occurs. The client can probe HadError() to determine the status. 00547 // 00548 // Note that every method of CodedOutputStream which writes some data has 00549 // a corresponding static "ToArray" version. These versions write directly 00550 // to the provided buffer, returning a pointer past the last written byte. 00551 // They require that the buffer has sufficient capacity for the encoded data. 00552 // This allows an optimization where we check if an output stream has enough 00553 // space for an entire message before we start writing and, if there is, we 00554 // call only the ToArray methods to avoid doing bound checks for each 00555 // individual value. 00556 // i.e., in the example above: 00557 // 00558 // CodedOutputStream coded_output = new CodedOutputStream(raw_output); 00559 // int magic_number = 1234; 00560 // char text[] = "Hello world!"; 00561 // 00562 // int coded_size = sizeof(magic_number) + 00563 // CodedOutputStream::Varint32Size(strlen(text)) + 00564 // strlen(text); 00565 // 00566 // uint8* buffer = 00567 // coded_output->GetDirectBufferForNBytesAndAdvance(coded_size); 00568 // if (buffer != NULL) { 00569 // // The output stream has enough space in the buffer: write directly to 00570 // // the array. 00571 // buffer = CodedOutputStream::WriteLittleEndian32ToArray(magic_number, 00572 // buffer); 00573 // buffer = CodedOutputStream::WriteVarint32ToArray(strlen(text), buffer); 00574 // buffer = CodedOutputStream::WriteRawToArray(text, strlen(text), buffer); 00575 // } else { 00576 // // Make bound-checked writes, which will ask the underlying stream for 00577 // // more space as needed. 00578 // coded_output->WriteLittleEndian32(magic_number); 00579 // coded_output->WriteVarint32(strlen(text)); 00580 // coded_output->WriteRaw(text, strlen(text)); 00581 // } 00582 // 00583 // delete coded_output; 00584 class LIBPROTOBUF_EXPORT CodedOutputStream { 00585 public: 00586 // Create an CodedOutputStream that writes to the given ZeroCopyOutputStream. 00587 explicit CodedOutputStream(ZeroCopyOutputStream* output); 00588 00589 // Destroy the CodedOutputStream and position the underlying 00590 // ZeroCopyOutputStream immediately after the last byte written. 00591 ~CodedOutputStream(); 00592 00593 // Skips a number of bytes, leaving the bytes unmodified in the underlying 00594 // buffer. Returns false if an underlying write error occurs. This is 00595 // mainly useful with GetDirectBufferPointer(). 00596 bool Skip(int count); 00597 00598 // Sets *data to point directly at the unwritten part of the 00599 // CodedOutputStream's underlying buffer, and *size to the size of that 00600 // buffer, but does not advance the stream's current position. This will 00601 // always either produce a non-empty buffer or return false. If the caller 00602 // writes any data to this buffer, it should then call Skip() to skip over 00603 // the consumed bytes. This may be useful for implementing external fast 00604 // serialization routines for types of data not covered by the 00605 // CodedOutputStream interface. 00606 bool GetDirectBufferPointer(void** data, int* size); 00607 00608 // If there are at least "size" bytes available in the current buffer, 00609 // returns a pointer directly into the buffer and advances over these bytes. 00610 // The caller may then write directly into this buffer (e.g. using the 00611 // *ToArray static methods) rather than go through CodedOutputStream. If 00612 // there are not enough bytes available, returns NULL. The return pointer is 00613 // invalidated as soon as any other non-const method of CodedOutputStream 00614 // is called. 00615 inline uint8* GetDirectBufferForNBytesAndAdvance(int size); 00616 00617 // Write raw bytes, copying them from the given buffer. 00618 void WriteRaw(const void* buffer, int size); 00619 // Like WriteRaw() but writing directly to the target array. 00620 // This is _not_ inlined, as the compiler often optimizes memcpy into inline 00621 // copy loops. Since this gets called by every field with string or bytes 00622 // type, inlining may lead to a significant amount of code bloat, with only a 00623 // minor performance gain. 00624 static uint8* WriteRawToArray(const void* buffer, int size, uint8* target); 00625 00626 // Equivalent to WriteRaw(str.data(), str.size()). 00627 void WriteString(const string& str); 00628 // Like WriteString() but writing directly to the target array. 00629 static uint8* WriteStringToArray(const string& str, uint8* target); 00630 00631 00632 // Write a 32-bit little-endian integer. 00633 void WriteLittleEndian32(uint32 value); 00634 // Like WriteLittleEndian32() but writing directly to the target array. 00635 static uint8* WriteLittleEndian32ToArray(uint32 value, uint8* target); 00636 // Write a 64-bit little-endian integer. 00637 void WriteLittleEndian64(uint64 value); 00638 // Like WriteLittleEndian64() but writing directly to the target array. 00639 static uint8* WriteLittleEndian64ToArray(uint64 value, uint8* target); 00640 00641 // Write an unsigned integer with Varint encoding. Writing a 32-bit value 00642 // is equivalent to casting it to uint64 and writing it as a 64-bit value, 00643 // but may be more efficient. 00644 void WriteVarint32(uint32 value); 00645 // Like WriteVarint32() but writing directly to the target array. 00646 static uint8* WriteVarint32ToArray(uint32 value, uint8* target); 00647 // Write an unsigned integer with Varint encoding. 00648 void WriteVarint64(uint64 value); 00649 // Like WriteVarint64() but writing directly to the target array. 00650 static uint8* WriteVarint64ToArray(uint64 value, uint8* target); 00651 00652 // Equivalent to WriteVarint32() except when the value is negative, 00653 // in which case it must be sign-extended to a full 10 bytes. 00654 void WriteVarint32SignExtended(int32 value); 00655 // Like WriteVarint32SignExtended() but writing directly to the target array. 00656 static uint8* WriteVarint32SignExtendedToArray(int32 value, uint8* target); 00657 00658 // This is identical to WriteVarint32(), but optimized for writing tags. 00659 // In particular, if the input is a compile-time constant, this method 00660 // compiles down to a couple instructions. 00661 // Always inline because otherwise the aformentioned optimization can't work, 00662 // but GCC by default doesn't want to inline this. 00663 void WriteTag(uint32 value); 00664 // Like WriteTag() but writing directly to the target array. 00665 static uint8* WriteTagToArray( 00666 uint32 value, uint8* target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; 00667 00668 // Returns the number of bytes needed to encode the given value as a varint. 00669 static int VarintSize32(uint32 value); 00670 // Returns the number of bytes needed to encode the given value as a varint. 00671 static int VarintSize64(uint64 value); 00672 00673 // If negative, 10 bytes. Otheriwse, same as VarintSize32(). 00674 static int VarintSize32SignExtended(int32 value); 00675 00676 // Returns the total number of bytes written since this object was created. 00677 inline int ByteCount() const; 00678 00679 // Returns true if there was an underlying I/O error since this object was 00680 // created. 00681 bool HadError() const { return had_error_; } 00682 00683 private: 00684 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedOutputStream); 00685 00686 ZeroCopyOutputStream* output_; 00687 uint8* buffer_; 00688 int buffer_size_; 00689 int total_bytes_; // Sum of sizes of all buffers seen so far. 00690 bool had_error_; // Whether an error occurred during output. 00691 00692 // Advance the buffer by a given number of bytes. 00693 void Advance(int amount); 00694 00695 // Called when the buffer runs out to request more data. Implies an 00696 // Advance(buffer_size_). 00697 bool Refresh(); 00698 00699 static uint8* WriteVarint32FallbackToArray(uint32 value, uint8* target); 00700 00701 // Always-inlined versions of WriteVarint* functions so that code can be 00702 // reused, while still controlling size. For instance, WriteVarint32ToArray() 00703 // should not directly call this: since it is inlined itself, doing so 00704 // would greatly increase the size of generated code. Instead, it should call 00705 // WriteVarint32FallbackToArray. Meanwhile, WriteVarint32() is already 00706 // out-of-line, so it should just invoke this directly to avoid any extra 00707 // function call overhead. 00708 static uint8* WriteVarint32FallbackToArrayInline( 00709 uint32 value, uint8* target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; 00710 static uint8* WriteVarint64ToArrayInline( 00711 uint64 value, uint8* target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; 00712 00713 static int VarintSize32Fallback(uint32 value); 00714 }; 00715 00716 // inline methods ==================================================== 00717 // The vast majority of varints are only one byte. These inline 00718 // methods optimize for that case. 00719 00720 inline bool CodedInputStream::ReadVarint32(uint32* value) { 00721 if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && *buffer_ < 0x80) { 00722 *value = *buffer_; 00723 Advance(1); 00724 return true; 00725 } else { 00726 return ReadVarint32Fallback(value); 00727 } 00728 } 00729 00730 inline bool CodedInputStream::ReadVarint64(uint64* value) { 00731 if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && *buffer_ < 0x80) { 00732 *value = *buffer_; 00733 Advance(1); 00734 return true; 00735 } else { 00736 return ReadVarint64Fallback(value); 00737 } 00738 } 00739 00740 // static 00741 inline const uint8* CodedInputStream::ReadLittleEndian32FromArray( 00742 const uint8* buffer, 00743 uint32* value) { 00744 #if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \ 00745 defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN 00746 memcpy(value, buffer, sizeof(*value)); 00747 return buffer + sizeof(*value); 00748 #else 00749 *value = (static_cast<uint32>(buffer[0]) ) | 00750 (static_cast<uint32>(buffer[1]) << 8) | 00751 (static_cast<uint32>(buffer[2]) << 16) | 00752 (static_cast<uint32>(buffer[3]) << 24); 00753 return buffer + sizeof(*value); 00754 #endif 00755 } 00756 // static 00757 inline const uint8* CodedInputStream::ReadLittleEndian64FromArray( 00758 const uint8* buffer, 00759 uint64* value) { 00760 #if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \ 00761 defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN 00762 memcpy(value, buffer, sizeof(*value)); 00763 return buffer + sizeof(*value); 00764 #else 00765 uint32 part0 = (static_cast<uint32>(buffer[0]) ) | 00766 (static_cast<uint32>(buffer[1]) << 8) | 00767 (static_cast<uint32>(buffer[2]) << 16) | 00768 (static_cast<uint32>(buffer[3]) << 24); 00769 uint32 part1 = (static_cast<uint32>(buffer[4]) ) | 00770 (static_cast<uint32>(buffer[5]) << 8) | 00771 (static_cast<uint32>(buffer[6]) << 16) | 00772 (static_cast<uint32>(buffer[7]) << 24); 00773 *value = static_cast<uint64>(part0) | 00774 (static_cast<uint64>(part1) << 32); 00775 return buffer + sizeof(*value); 00776 #endif 00777 } 00778 00779 inline bool CodedInputStream::ReadLittleEndian32(uint32* value) { 00780 #if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \ 00781 defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN 00782 if (GOOGLE_PREDICT_TRUE(BufferSize() >= sizeof(*value))) { 00783 memcpy(value, buffer_, sizeof(*value)); 00784 Advance(sizeof(*value)); 00785 return true; 00786 } else { 00787 return ReadLittleEndian32Fallback(value); 00788 } 00789 #else 00790 return ReadLittleEndian32Fallback(value); 00791 #endif 00792 } 00793 00794 inline bool CodedInputStream::ReadLittleEndian64(uint64* value) { 00795 #if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \ 00796 defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN 00797 if (GOOGLE_PREDICT_TRUE(BufferSize() >= sizeof(*value))) { 00798 memcpy(value, buffer_, sizeof(*value)); 00799 Advance(sizeof(*value)); 00800 return true; 00801 } else { 00802 return ReadLittleEndian64Fallback(value); 00803 } 00804 #else 00805 return ReadLittleEndian64Fallback(value); 00806 #endif 00807 } 00808 00809 inline uint32 CodedInputStream::ReadTag() { 00810 if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && buffer_[0] < 0x80) { 00811 last_tag_ = buffer_[0]; 00812 Advance(1); 00813 return last_tag_; 00814 } else { 00815 last_tag_ = ReadTagFallback(); 00816 return last_tag_; 00817 } 00818 } 00819 00820 inline bool CodedInputStream::LastTagWas(uint32 expected) { 00821 return last_tag_ == expected; 00822 } 00823 00824 inline bool CodedInputStream::ConsumedEntireMessage() { 00825 return legitimate_message_end_; 00826 } 00827 00828 inline bool CodedInputStream::ExpectTag(uint32 expected) { 00829 if (expected < (1 << 7)) { 00830 if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && buffer_[0] == expected) { 00831 Advance(1); 00832 return true; 00833 } else { 00834 return false; 00835 } 00836 } else if (expected < (1 << 14)) { 00837 if (GOOGLE_PREDICT_TRUE(BufferSize() >= 2) && 00838 buffer_[0] == static_cast<uint8>(expected | 0x80) && 00839 buffer_[1] == static_cast<uint8>(expected >> 7)) { 00840 Advance(2); 00841 return true; 00842 } else { 00843 return false; 00844 } 00845 } else { 00846 // Don't bother optimizing for larger values. 00847 return false; 00848 } 00849 } 00850 00851 inline const uint8* CodedInputStream::ExpectTagFromArray( 00852 const uint8* buffer, uint32 expected) { 00853 if (expected < (1 << 7)) { 00854 if (buffer[0] == expected) { 00855 return buffer + 1; 00856 } 00857 } else if (expected < (1 << 14)) { 00858 if (buffer[0] == static_cast<uint8>(expected | 0x80) && 00859 buffer[1] == static_cast<uint8>(expected >> 7)) { 00860 return buffer + 2; 00861 } 00862 } 00863 return NULL; 00864 } 00865 00866 inline void CodedInputStream::GetDirectBufferPointerInline(const void** data, 00867 int* size) { 00868 *data = buffer_; 00869 *size = buffer_end_ - buffer_; 00870 } 00871 00872 inline bool CodedInputStream::ExpectAtEnd() { 00873 // If we are at a limit we know no more bytes can be read. Otherwise, it's 00874 // hard to say without calling Refresh(), and we'd rather not do that. 00875 00876 if (buffer_ == buffer_end_ && buffer_size_after_limit_ != 0) { 00877 last_tag_ = 0; // Pretend we called ReadTag()... 00878 legitimate_message_end_ = true; // ... and it hit EOF. 00879 return true; 00880 } else { 00881 return false; 00882 } 00883 } 00884 00885 inline uint8* CodedOutputStream::GetDirectBufferForNBytesAndAdvance(int size) { 00886 if (buffer_size_ < size) { 00887 return NULL; 00888 } else { 00889 uint8* result = buffer_; 00890 Advance(size); 00891 return result; 00892 } 00893 } 00894 00895 inline uint8* CodedOutputStream::WriteVarint32ToArray(uint32 value, 00896 uint8* target) { 00897 if (value < 0x80) { 00898 *target = value; 00899 return target + 1; 00900 } else { 00901 return WriteVarint32FallbackToArray(value, target); 00902 } 00903 } 00904 00905 inline void CodedOutputStream::WriteVarint32SignExtended(int32 value) { 00906 if (value < 0) { 00907 WriteVarint64(static_cast<uint64>(value)); 00908 } else { 00909 WriteVarint32(static_cast<uint32>(value)); 00910 } 00911 } 00912 00913 inline uint8* CodedOutputStream::WriteVarint32SignExtendedToArray( 00914 int32 value, uint8* target) { 00915 if (value < 0) { 00916 return WriteVarint64ToArray(static_cast<uint64>(value), target); 00917 } else { 00918 return WriteVarint32ToArray(static_cast<uint32>(value), target); 00919 } 00920 } 00921 00922 inline uint8* CodedOutputStream::WriteLittleEndian32ToArray(uint32 value, 00923 uint8* target) { 00924 #if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \ 00925 defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN 00926 memcpy(target, &value, sizeof(value)); 00927 #else 00928 target[0] = static_cast<uint8>(value); 00929 target[1] = static_cast<uint8>(value >> 8); 00930 target[2] = static_cast<uint8>(value >> 16); 00931 target[3] = static_cast<uint8>(value >> 24); 00932 #endif 00933 return target + sizeof(value); 00934 } 00935 00936 inline uint8* CodedOutputStream::WriteLittleEndian64ToArray(uint64 value, 00937 uint8* target) { 00938 #if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \ 00939 defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN 00940 memcpy(target, &value, sizeof(value)); 00941 #else 00942 uint32 part0 = static_cast<uint32>(value); 00943 uint32 part1 = static_cast<uint32>(value >> 32); 00944 00945 target[0] = static_cast<uint8>(part0); 00946 target[1] = static_cast<uint8>(part0 >> 8); 00947 target[2] = static_cast<uint8>(part0 >> 16); 00948 target[3] = static_cast<uint8>(part0 >> 24); 00949 target[4] = static_cast<uint8>(part1); 00950 target[5] = static_cast<uint8>(part1 >> 8); 00951 target[6] = static_cast<uint8>(part1 >> 16); 00952 target[7] = static_cast<uint8>(part1 >> 24); 00953 #endif 00954 return target + sizeof(value); 00955 } 00956 00957 inline void CodedOutputStream::WriteTag(uint32 value) { 00958 WriteVarint32(value); 00959 } 00960 00961 inline uint8* CodedOutputStream::WriteTagToArray( 00962 uint32 value, uint8* target) { 00963 if (value < (1 << 7)) { 00964 target[0] = value; 00965 return target + 1; 00966 } else if (value < (1 << 14)) { 00967 target[0] = static_cast<uint8>(value | 0x80); 00968 target[1] = static_cast<uint8>(value >> 7); 00969 return target + 2; 00970 } else { 00971 return WriteVarint32FallbackToArray(value, target); 00972 } 00973 } 00974 00975 inline int CodedOutputStream::VarintSize32(uint32 value) { 00976 if (value < (1 << 7)) { 00977 return 1; 00978 } else { 00979 return VarintSize32Fallback(value); 00980 } 00981 } 00982 00983 inline int CodedOutputStream::VarintSize32SignExtended(int32 value) { 00984 if (value < 0) { 00985 return 10; // TODO(kenton): Make this a symbolic constant. 00986 } else { 00987 return VarintSize32(static_cast<uint32>(value)); 00988 } 00989 } 00990 00991 inline void CodedOutputStream::WriteString(const string& str) { 00992 WriteRaw(str.data(), str.size()); 00993 } 00994 00995 inline uint8* CodedOutputStream::WriteStringToArray( 00996 const string& str, uint8* target) { 00997 return WriteRawToArray(str.data(), str.size(), target); 00998 } 00999 01000 inline int CodedOutputStream::ByteCount() const { 01001 return total_bytes_ - buffer_size_; 01002 } 01003 01004 inline void CodedInputStream::Advance(int amount) { 01005 buffer_ += amount; 01006 } 01007 01008 inline void CodedOutputStream::Advance(int amount) { 01009 buffer_ += amount; 01010 buffer_size_ -= amount; 01011 } 01012 01013 inline void CodedInputStream::SetRecursionLimit(int limit) { 01014 recursion_limit_ = limit; 01015 } 01016 01017 inline bool CodedInputStream::IncrementRecursionDepth() { 01018 ++recursion_depth_; 01019 return recursion_depth_ <= recursion_limit_; 01020 } 01021 01022 inline void CodedInputStream::DecrementRecursionDepth() { 01023 if (recursion_depth_ > 0) --recursion_depth_; 01024 } 01025 01026 inline void CodedInputStream::SetExtensionRegistry(DescriptorPool* pool, 01027 MessageFactory* factory) { 01028 extension_pool_ = pool; 01029 extension_factory_ = factory; 01030 } 01031 01032 inline const DescriptorPool* CodedInputStream::GetExtensionPool() { 01033 return extension_pool_; 01034 } 01035 01036 inline MessageFactory* CodedInputStream::GetExtensionFactory() { 01037 return extension_factory_; 01038 } 01039 01040 inline int CodedInputStream::BufferSize() const { 01041 return buffer_end_ - buffer_; 01042 } 01043 01044 inline CodedInputStream::CodedInputStream(ZeroCopyInputStream* input) 01045 : input_(input), 01046 buffer_(NULL), 01047 buffer_end_(NULL), 01048 total_bytes_read_(0), 01049 overflow_bytes_(0), 01050 last_tag_(0), 01051 legitimate_message_end_(false), 01052 aliasing_enabled_(false), 01053 current_limit_(INT_MAX), 01054 buffer_size_after_limit_(0), 01055 total_bytes_limit_(kDefaultTotalBytesLimit), 01056 total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold), 01057 recursion_depth_(0), 01058 recursion_limit_(kDefaultRecursionLimit), 01059 extension_pool_(NULL), 01060 extension_factory_(NULL) { 01061 // Eagerly Refresh() so buffer space is immediately available. 01062 Refresh(); 01063 } 01064 01065 inline CodedInputStream::CodedInputStream(const uint8* buffer, int size) 01066 : input_(NULL), 01067 buffer_(buffer), 01068 buffer_end_(buffer + size), 01069 total_bytes_read_(size), 01070 overflow_bytes_(0), 01071 last_tag_(0), 01072 legitimate_message_end_(false), 01073 aliasing_enabled_(false), 01074 current_limit_(size), 01075 buffer_size_after_limit_(0), 01076 total_bytes_limit_(kDefaultTotalBytesLimit), 01077 total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold), 01078 recursion_depth_(0), 01079 recursion_limit_(kDefaultRecursionLimit), 01080 extension_pool_(NULL), 01081 extension_factory_(NULL) { 01082 // Note that setting current_limit_ == size is important to prevent some 01083 // code paths from trying to access input_ and segfaulting. 01084 } 01085 01086 inline CodedInputStream::~CodedInputStream() { 01087 if (input_ != NULL) { 01088 BackUpInputToCurrentPosition(); 01089 } 01090 } 01091 01092 } // namespace io 01093 } // namespace protobuf 01094 01095 } // namespace google 01096 #endif // GOOGLE_PROTOBUF_IO_CODED_STREAM_H__