• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_MESSAGE_H__
9 #define GOOGLE_PROTOBUF_COMPILER_CSHARP_MESSAGE_H__
10 
11 #include <string>
12 #include <vector>
13 
14 #include "google/protobuf/compiler/code_generator.h"
15 #include "google/protobuf/compiler/csharp/csharp_source_generator_base.h"
16 #include "google/protobuf/compiler/csharp/csharp_helpers.h"
17 
18 namespace google {
19 namespace protobuf {
20 namespace compiler {
21 namespace csharp {
22 
23 class FieldGeneratorBase;
24 
25 class MessageGenerator : public SourceGeneratorBase {
26  public:
27   MessageGenerator(const Descriptor* descriptor, const Options* options);
28   ~MessageGenerator();
29 
30   MessageGenerator(const MessageGenerator&) = delete;
31   MessageGenerator& operator=(const MessageGenerator&) = delete;
32 
33   void GenerateCloningCode(io::Printer* printer);
34   void GenerateFreezingCode(io::Printer* printer);
35   void GenerateFrameworkMethods(io::Printer* printer);
36   void Generate(io::Printer* printer);
37 
38  private:
39   const Descriptor* descriptor_;
40   std::vector<const FieldDescriptor*> fields_by_number_;
41   int has_bit_field_count_;
42   bool has_extension_ranges_;
43 
44   void GenerateMessageSerializationMethods(io::Printer* printer);
45   void GenerateWriteToBody(io::Printer* printer, bool use_write_context);
46   void GenerateMergingMethods(io::Printer* printer);
47   void GenerateMainParseLoop(io::Printer* printer, bool use_parse_context);
48 
49   int GetPresenceIndex(const FieldDescriptor* descriptor);
50   FieldGeneratorBase* CreateFieldGeneratorInternal(
51       const FieldDescriptor* descriptor);
52 
53   bool HasNestedGeneratedTypes();
54 
55   void AddDeprecatedFlag(io::Printer* printer);
56   void AddSerializableAttribute(io::Printer* printer);
57 
58   std::string class_name();
59   std::string full_class_name();
60 
61   // field descriptors sorted by number
62   const std::vector<const FieldDescriptor*>& fields_by_number();
63 };
64 
65 }  // namespace csharp
66 }  // namespace compiler
67 }  // namespace protobuf
68 }  // namespace google
69 
70 #endif  // GOOGLE_PROTOBUF_COMPILER_CSHARP_MESSAGE_H__
71