• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 //     * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //     * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 //     * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 // Author: kenton@google.com (Kenton Varda)
32 // Author: jonp@google.com (Jon Perlow)
33 //  Based on original Protocol Buffers design by
34 //  Sanjay Ghemawat, Jeff Dean, and others.
35 
36 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_LITE_H__
37 #define GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_LITE_H__
38 
39 #include <cstdint>
40 #include <map>
41 #include <string>
42 
43 #include <google/protobuf/compiler/java/java_field.h>
44 
45 namespace google {
46 namespace protobuf {
47 namespace compiler {
48 namespace java {
49 class Context;            // context.h
50 class ClassNameResolver;  // name_resolver.h
51 }  // namespace java
52 }  // namespace compiler
53 }  // namespace protobuf
54 }  // namespace google
55 
56 namespace google {
57 namespace protobuf {
58 namespace compiler {
59 namespace java {
60 
61 class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator {
62  public:
63   explicit ImmutableStringFieldLiteGenerator(const FieldDescriptor* descriptor,
64                                              int messageBitIndex,
65                                              Context* context);
66   ~ImmutableStringFieldLiteGenerator() override;
67 
68   // implements ImmutableFieldLiteGenerator
69   // ------------------------------------
70   int GetNumBitsForMessage() const override;
71   void GenerateInterfaceMembers(io::Printer* printer) const override;
72   void GenerateMembers(io::Printer* printer) const override;
73   void GenerateBuilderMembers(io::Printer* printer) const override;
74   void GenerateInitializationCode(io::Printer* printer) const override;
75   void GenerateFieldInfo(io::Printer* printer,
76                          std::vector<uint16_t>* output) const override;
77   void GenerateKotlinDslMembers(io::Printer* printer) const override;
78 
79   std::string GetBoxedType() const override;
80 
81  protected:
82   const FieldDescriptor* descriptor_;
83   std::map<std::string, std::string> variables_;
84   const int messageBitIndex_;
85   ClassNameResolver* name_resolver_;
86 
87  private:
88   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringFieldLiteGenerator);
89 };
90 
91 class ImmutableStringOneofFieldLiteGenerator
92     : public ImmutableStringFieldLiteGenerator {
93  public:
94   ImmutableStringOneofFieldLiteGenerator(const FieldDescriptor* descriptor,
95                                          int messageBitIndex, Context* context);
96   ~ImmutableStringOneofFieldLiteGenerator() override;
97 
98  private:
99   void GenerateMembers(io::Printer* printer) const override;
100   void GenerateBuilderMembers(io::Printer* printer) const override;
101   void GenerateFieldInfo(io::Printer* printer,
102                          std::vector<uint16_t>* output) const override;
103 
104   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringOneofFieldLiteGenerator);
105 };
106 
107 class RepeatedImmutableStringFieldLiteGenerator
108     : public ImmutableFieldLiteGenerator {
109  public:
110   explicit RepeatedImmutableStringFieldLiteGenerator(
111       const FieldDescriptor* descriptor, int messageBitIndex, Context* context);
112   ~RepeatedImmutableStringFieldLiteGenerator() override;
113 
114   // implements ImmutableFieldLiteGenerator ------------------------------------
115   int GetNumBitsForMessage() const override;
116   void GenerateInterfaceMembers(io::Printer* printer) const override;
117   void GenerateMembers(io::Printer* printer) const override;
118   void GenerateBuilderMembers(io::Printer* printer) const override;
119   void GenerateInitializationCode(io::Printer* printer) const override;
120   void GenerateFieldInfo(io::Printer* printer,
121                          std::vector<uint16_t>* output) const override;
122   void GenerateKotlinDslMembers(io::Printer* printer) const override;
123 
124   std::string GetBoxedType() const override;
125 
126  private:
127   const FieldDescriptor* descriptor_;
128   std::map<std::string, std::string> variables_;
129   ClassNameResolver* name_resolver_;
130 
131   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableStringFieldLiteGenerator);
132 };
133 
134 }  // namespace java
135 }  // namespace compiler
136 }  // namespace protobuf
137 }  // namespace google
138 
139 #endif  // GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_LITE_H__
140