csharp_enum_field.cc
Go to the documentation of this file.
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 #include <sstream>
32 
38 
43 
44 namespace google {
45 namespace protobuf {
46 namespace compiler {
47 namespace csharp {
48 
50  int presenceIndex, const Options *options)
51  : PrimitiveFieldGenerator(descriptor, presenceIndex, options) {
52 }
53 
55 }
56 
58  printer->Print(variables_,
59  "$property_name$ = ($type_name$) input.ReadEnum();\n");
60 }
61 
63  printer->Print(variables_,
64  "if ($has_property_check$) {\n"
65  " output.WriteRawTag($tag_bytes$);\n"
66  " output.WriteEnum((int) $property_name$);\n"
67  "}\n");
68 }
69 
71  printer->Print(
72  variables_,
73  "if ($has_property_check$) {\n"
74  " size += $tag_size$ + pb::CodedOutputStream.ComputeEnumSize((int) $property_name$);\n"
75  "}\n");
76 }
77 
79  printer->Print(
80  variables_,
81  "pb::FieldCodec.ForEnum($tag$, x => (int) x, x => ($type_name$) x, $default_value$)");
82 }
83 
86  AddDeprecatedFlag(printer);
87  printer->Print(
88  variables_,
89  "$access_level$ static readonly pb::Extension<$extended_type$, $type_name$> $property_name$ =\n"
90  " new pb::Extension<$extended_type$, $type_name$>($number$, ");
91  GenerateCodecCode(printer);
92  printer->Print(");\n");
93 }
94 
96  const FieldDescriptor* descriptor, int presenceIndex, const Options *options)
98 }
99 
101 }
102 
104  printer->Print(variables_, "$property_name$ = other.$property_name$;\n");
105 }
106 
108  // TODO(jonskeet): What about if we read the default value?
109  printer->Print(
110  variables_,
111  "$oneof_name$_ = input.ReadEnum();\n"
112  "$oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n");
113 }
114 
116  printer->Print(
117  variables_,
118  "if ($has_property_check$) {\n"
119  " output.WriteRawTag($tag_bytes$);\n"
120  " output.WriteEnum((int) $property_name$);\n"
121  "}\n");
122 }
123 
125  printer->Print(
126  variables_,
127  "if ($has_property_check$) {\n"
128  " size += $tag_size$ + pb::CodedOutputStream.ComputeEnumSize((int) $property_name$);\n"
129  "}\n");
130 }
131 
132 } // namespace csharp
133 } // namespace compiler
134 } // namespace protobuf
135 } // namespace google
zero_copy_stream.h
google::protobuf::io::Printer::Print
void Print(const std::map< std::string, std::string > &variables, const char *text)
Definition: printer.cc:112
google::protobuf::FieldDescriptor
Definition: src/google/protobuf/descriptor.h:515
google::protobuf::compiler::csharp::EnumOneofFieldGenerator::EnumOneofFieldGenerator
EnumOneofFieldGenerator(const FieldDescriptor *descriptor, int presenceIndex, const Options *options)
Definition: csharp_enum_field.cc:95
google::protobuf::compiler::csharp::PrimitiveFieldGenerator
Definition: csharp_primitive_field.h:46
options
Message * options
Definition: src/google/protobuf/descriptor.cc:3119
google::protobuf::compiler::csharp::EnumFieldGenerator::GenerateCodecCode
virtual void GenerateCodecCode(io::Printer *printer)
Definition: csharp_enum_field.cc:78
google::protobuf::compiler::csharp::EnumFieldGenerator::~EnumFieldGenerator
~EnumFieldGenerator()
Definition: csharp_enum_field.cc:54
google::protobuf::compiler::csharp::FieldGeneratorBase::descriptor_
const FieldDescriptor * descriptor_
Definition: csharp_field_base.h:73
descriptor
Descriptor * descriptor
Definition: php/ext/google/protobuf/protobuf.h:936
google::protobuf::compiler::csharp::FieldGeneratorBase::AddDeprecatedFlag
void AddDeprecatedFlag(io::Printer *printer)
Definition: csharp_field_base.cc:164
google::protobuf::compiler::csharp::FieldGeneratorBase::variables_
std::map< string, string > variables_
Definition: csharp_field_base.h:75
google::protobuf::compiler::csharp::EnumFieldGenerator::GenerateSerializationCode
virtual void GenerateSerializationCode(io::Printer *printer)
Definition: csharp_enum_field.cc:62
google::protobuf::compiler::csharp::Options
Definition: csharp_options.h:42
google::protobuf::compiler::csharp::PrimitiveOneofFieldGenerator
Definition: csharp_primitive_field.h:73
google::protobuf::compiler::csharp::EnumOneofFieldGenerator::~EnumOneofFieldGenerator
~EnumOneofFieldGenerator()
Definition: csharp_enum_field.cc:100
csharp_doc_comment.h
printer.h
google::protobuf::compiler::csharp::EnumOneofFieldGenerator::GenerateMergingCode
virtual void GenerateMergingCode(io::Printer *printer)
Definition: csharp_enum_field.cc:103
google::protobuf::compiler::csharp::EnumOneofFieldGenerator::GenerateParsingCode
virtual void GenerateParsingCode(io::Printer *printer)
Definition: csharp_enum_field.cc:107
google::protobuf::compiler::csharp::EnumFieldGenerator::GenerateSerializedSizeCode
virtual void GenerateSerializedSizeCode(io::Printer *printer)
Definition: csharp_enum_field.cc:70
code_generator.h
google::protobuf::io::Printer
Definition: printer.h:181
google::protobuf::compiler::csharp::EnumFieldGenerator::GenerateParsingCode
virtual void GenerateParsingCode(io::Printer *printer)
Definition: csharp_enum_field.cc:57
csharp_helpers.h
csharp_options.h
csharp_enum_field.h
google::protobuf::compiler::csharp::EnumOneofFieldGenerator::GenerateSerializationCode
virtual void GenerateSerializationCode(io::Printer *printer)
Definition: csharp_enum_field.cc:115
google::protobuf::compiler::csharp::EnumFieldGenerator::EnumFieldGenerator
EnumFieldGenerator(const FieldDescriptor *descriptor, int presenceIndex, const Options *options)
Definition: csharp_enum_field.cc:49
descriptor.h
google::protobuf::compiler::csharp::WritePropertyDocComment
void WritePropertyDocComment(io::Printer *printer, const FieldDescriptor *field)
Definition: csharp_doc_comment.cc:97
google::protobuf::compiler::csharp::EnumFieldGenerator::GenerateExtensionCode
virtual void GenerateExtensionCode(io::Printer *printer)
Definition: csharp_enum_field.cc:84
descriptor.pb.h
google::protobuf::compiler::csharp::EnumOneofFieldGenerator::GenerateSerializedSizeCode
virtual void GenerateSerializedSizeCode(io::Printer *printer)
Definition: csharp_enum_field.cc:124
compiler
Definition: plugin.pb.cc:22
google
Definition: data_proto2_to_proto3_util.h:11


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:49