// Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. // 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 // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Authors: [email protected] (Wink Saville), // [email protected] (Kenton Varda) // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. // // Defines MessageLite, the abstract interface implemented by all (lite // and non-lite) protocol message objects. #ifndef GOOGLE_PROTOBUF_MESSAGE_LITE_H__ #define GOOGLE_PROTOBUF_MESSAGE_LITE_H__ #include <climits> #include <string> #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/logging.h> #include <google/protobuf/io/coded_stream.h> #include <google/protobuf/arena.h> #include <google/protobuf/stubs/once.h> #include <google/protobuf/port.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/explicitly_constructed.h> #include <google/protobuf/metadata_lite.h> #include <google/protobuf/stubs/hash.h> // TODO(b/211442718): cleanup // clang-format off #include <google/protobuf/port_def.inc> // clang-format on #ifdef SWIG #error "You cannot SWIG proto headers" #endif namespace google { namespace protobuf { template <typename T> class RepeatedPtrField; class FastReflectionMessageMutator; class FastReflectionStringSetter; class Reflection; namespace io { class CodedInputStream; class CodedOutputStream; class ZeroCopyInputStream; class ZeroCopyOutputStream; } // namespace io namespace internal { class SwapFieldHelper; // See parse_context.h for explanation class ParseContext; class ExtensionSet; class LazyField; class RepeatedPtrFieldBase; class TcParser; class WireFormatLite; class WeakFieldMap; template <typename Type> class GenericTypeHandler; // defined in repeated_field.h // We compute sizes as size_t but cache them as int. This function converts a // computed size to a cached size. Since we don't proceed with serialization // if the total size was > INT_MAX, it is not important what this function // returns for inputs > INT_MAX. However this case should not error or // GOOGLE_CHECK-fail, because the full size_t resolution is still returned from // ByteSizeLong() and checked against INT_MAX; we can catch the overflow // there. inline int ToCachedSize(size_t size) { … } // We mainly calculate sizes in terms of size_t, but some functions that // compute sizes return "int". These int sizes are expected to always be // positive. This function is more efficient than casting an int to size_t // directly on 64-bit platforms because it avoids making the compiler emit a // sign extending instruction, which we don't want and don't want to pay for. inline size_t FromIntSize(int size) { … } // For cases where a legacy function returns an integer size. We GOOGLE_DCHECK() // that the conversion will fit within an integer; if this is false then we // are losing information. inline int ToIntSize(size_t size) { … } // Default empty string object. Don't use this directly. Instead, call // GetEmptyString() to get the reference. This empty string is aligned with a // minimum alignment of 8 bytes to match the requirement of ArenaStringPtr. PROTOBUF_EXPORT extern ExplicitlyConstructedArenaString fixed_address_empty_string; PROTOBUF_EXPORT constexpr const std::string& GetEmptyStringAlreadyInited() { … } PROTOBUF_EXPORT size_t StringSpaceUsedExcludingSelfLong(const std::string& str); } // namespace internal // Interface to light weight protocol messages. // // This interface is implemented by all protocol message objects. Non-lite // messages additionally implement the Message interface, which is a // subclass of MessageLite. Use MessageLite instead when you only need // the subset of features which it supports -- namely, nothing that uses // descriptors or reflection. You can instruct the protocol compiler // to generate classes which implement only MessageLite, not the full // Message interface, by adding the following line to the .proto file: // // option optimize_for = LITE_RUNTIME; // // This is particularly useful on resource-constrained systems where // the full protocol buffers runtime library is too big. // // Note that on non-constrained systems (e.g. servers) when you need // to link in lots of protocol definitions, a better way to reduce // total code footprint is to use optimize_for = CODE_SIZE. This // will make the generated code smaller while still supporting all the // same features (at the expense of speed). optimize_for = LITE_RUNTIME // is best when you only have a small number of message types linked // into your binary, in which case the size of the protocol buffers // runtime itself is the biggest problem. // // Users must not derive from this class. Only the protocol compiler and // the internal library are allowed to create subclasses. class PROTOBUF_EXPORT MessageLite { … }; namespace internal { template <bool alias> bool MergeFromImpl(StringPiece input, MessageLite* msg, MessageLite::ParseFlags parse_flags); extern template bool MergeFromImpl<false>(StringPiece input, MessageLite* msg, MessageLite::ParseFlags parse_flags); extern template bool MergeFromImpl<true>(StringPiece input, MessageLite* msg, MessageLite::ParseFlags parse_flags); template <bool alias> bool MergeFromImpl(io::ZeroCopyInputStream* input, MessageLite* msg, MessageLite::ParseFlags parse_flags); extern template bool MergeFromImpl<false>(io::ZeroCopyInputStream* input, MessageLite* msg, MessageLite::ParseFlags parse_flags); extern template bool MergeFromImpl<true>(io::ZeroCopyInputStream* input, MessageLite* msg, MessageLite::ParseFlags parse_flags); struct BoundedZCIS { … }; template <bool alias> bool MergeFromImpl(BoundedZCIS input, MessageLite* msg, MessageLite::ParseFlags parse_flags); extern template bool MergeFromImpl<false>(BoundedZCIS input, MessageLite* msg, MessageLite::ParseFlags parse_flags); extern template bool MergeFromImpl<true>(BoundedZCIS input, MessageLite* msg, MessageLite::ParseFlags parse_flags); template <typename T> struct SourceWrapper; template <bool alias, typename T> bool MergeFromImpl(const SourceWrapper<T>& input, MessageLite* msg, MessageLite::ParseFlags parse_flags) { … } } // namespace internal template <MessageLite::ParseFlags flags, typename T> bool MessageLite::ParseFrom(const T& input) { … } // =================================================================== // Shutdown support. // Shut down the entire protocol buffers library, deleting all static-duration // objects allocated by the library or by generated .pb.cc files. // // There are two reasons you might want to call this: // * You use a draconian definition of "memory leak" in which you expect // every single malloc() to have a corresponding free(), even for objects // which live until program exit. // * You are writing a dynamically-loaded library which needs to clean up // after itself when the library is unloaded. // // It is safe to call this multiple times. However, it is not safe to use // any other part of the protocol buffers library after // ShutdownProtobufLibrary() has been called. Furthermore this call is not // thread safe, user needs to synchronize multiple calls. PROTOBUF_EXPORT void ShutdownProtobufLibrary(); namespace internal { // Register a function to be called when ShutdownProtocolBuffers() is called. PROTOBUF_EXPORT void OnShutdown(void (*func)()); // Run an arbitrary function on an arg PROTOBUF_EXPORT void OnShutdownRun(void (*f)(const void*), const void* arg); template <typename T> T* OnShutdownDelete(T* p) { … } } // namespace internal } // namespace protobuf } // namespace google #include <google/protobuf/port_undef.inc> #endif // GOOGLE_PROTOBUF_MESSAGE_LITE_H__