1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2008 Google Inc. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 // Author: kenton@google.com (Kenton Varda) 9 // Based on original Protocol Buffers design by 10 // Sanjay Ghemawat, Jeff Dean, and others. 11 // 12 // This header is logically internal, but is made public because it is used 13 // from protocol-compiler-generated code, which may reside in other components. 14 15 #ifndef GOOGLE_PROTOBUF_REFLECTION_OPS_H__ 16 #define GOOGLE_PROTOBUF_REFLECTION_OPS_H__ 17 18 #include "google/protobuf/message.h" 19 #include "google/protobuf/port.h" 20 21 #ifdef SWIG 22 #error "You cannot SWIG proto headers" 23 #endif 24 25 // Must be included last. 26 #include "google/protobuf/port_def.inc" 27 28 namespace google { 29 namespace protobuf { 30 namespace internal { 31 32 // Basic operations that can be performed using reflection. 33 // These can be used as a cheap way to implement the corresponding 34 // methods of the Message interface, though they are likely to be 35 // slower than implementations tailored for the specific message type. 36 // 37 // This class should stay limited to operations needed to implement 38 // the Message interface. 39 // 40 // This class is really a namespace that contains only static methods. 41 class PROTOBUF_EXPORT ReflectionOps { 42 public: 43 ReflectionOps() = delete; 44 45 static void Copy(const Message& from, Message* to); 46 static void Merge(const Message& from, Message* to); 47 static void Clear(Message* message); 48 static bool IsInitialized(const Message& message); 49 static bool IsInitialized(const Message& message, bool check_fields, 50 bool check_descendants); 51 static void DiscardUnknownFields(Message* message); 52 53 // Finds all unset required fields in the message and adds their full 54 // paths (e.g. "foo.bar[5].baz") to *names. "prefix" will be attached to 55 // the front of each name. 56 static void FindInitializationErrors(const Message& message, 57 const std::string& prefix, 58 std::vector<std::string>* errors); 59 }; 60 61 } // namespace internal 62 } // namespace protobuf 63 } // namespace google 64 65 #include "google/protobuf/port_undef.inc" 66 67 #endif // GOOGLE_PROTOBUF_REFLECTION_OPS_H__ 68