File indexing completed on 2025-01-31 10:11:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_HELPERS_H__
0013 #define GOOGLE_PROTOBUF_COMPILER_CSHARP_HELPERS_H__
0014
0015 #include <string>
0016
0017 #include "google/protobuf/compiler/code_generator.h"
0018 #include "absl/strings/string_view.h"
0019 #include "google/protobuf/compiler/csharp/names.h"
0020 #include "google/protobuf/descriptor.h"
0021 #include "google/protobuf/descriptor.pb.h"
0022 #include "google/protobuf/io/printer.h"
0023 #include "google/protobuf/port.h"
0024 #include "google/protobuf/port_def.inc"
0025 #include "google/protobuf/stubs/common.h"
0026
0027 namespace google {
0028 namespace protobuf {
0029 namespace compiler {
0030 namespace csharp {
0031
0032 struct Options;
0033 class FieldGeneratorBase;
0034
0035
0036 enum CSharpType {
0037 CSHARPTYPE_INT32 = 1,
0038 CSHARPTYPE_INT64 = 2,
0039 CSHARPTYPE_UINT32 = 3,
0040 CSHARPTYPE_UINT64 = 4,
0041 CSHARPTYPE_FLOAT = 5,
0042 CSHARPTYPE_DOUBLE = 6,
0043 CSHARPTYPE_BOOL = 7,
0044 CSHARPTYPE_STRING = 8,
0045 CSHARPTYPE_BYTESTRING = 9,
0046 CSHARPTYPE_MESSAGE = 10,
0047 CSHARPTYPE_ENUM = 11,
0048 MAX_CSHARPTYPE = 11
0049 };
0050
0051
0052 CSharpType GetCSharpType(FieldDescriptor::Type type);
0053
0054 std::string GetFieldName(const FieldDescriptor* descriptor);
0055
0056 std::string GetFieldConstantName(const FieldDescriptor* field);
0057
0058 std::string GetPropertyName(const FieldDescriptor* descriptor);
0059
0060 std::string GetOneofCaseName(const FieldDescriptor* descriptor);
0061
0062 int GetFixedSize(FieldDescriptor::Type type);
0063
0064
0065
0066 std::string PROTOC_EXPORT GetEnumValueName(absl::string_view enum_name,
0067 absl::string_view enum_value_name);
0068
0069
0070 std::string StringToBase64(absl::string_view input);
0071
0072 std::string FileDescriptorToBase64(const FileDescriptor* descriptor);
0073
0074 FieldGeneratorBase* CreateFieldGenerator(const FieldDescriptor* descriptor,
0075 int presenceIndex,
0076 const Options* options);
0077
0078 std::string GetFullExtensionName(const FieldDescriptor* descriptor);
0079
0080 bool IsNullable(const FieldDescriptor* descriptor);
0081
0082
0083
0084 inline bool IsMapEntryMessage(const Descriptor* descriptor) {
0085 return descriptor->options().map_entry();
0086 }
0087
0088
0089
0090
0091 inline bool IsDescriptorProto(const FileDescriptor* descriptor) {
0092 return descriptor->name() == "google/protobuf/descriptor.proto" ||
0093 descriptor->name() == "net/proto2/proto/descriptor.proto";
0094 }
0095
0096
0097 inline bool IsDescriptorOptionMessage(const Descriptor* descriptor) {
0098 if (!IsDescriptorProto(descriptor->file())) {
0099 return false;
0100 }
0101 const absl::string_view name = descriptor->name();
0102 return name == "FileOptions" ||
0103 name == "MessageOptions" ||
0104 name == "FieldOptions" ||
0105 name == "OneofOptions" ||
0106 name == "EnumOptions" ||
0107 name == "EnumValueOptions" ||
0108 name == "ServiceOptions" ||
0109 name == "MethodOptions";
0110 }
0111
0112 inline bool IsWrapperType(const FieldDescriptor* descriptor) {
0113 return descriptor->type() == FieldDescriptor::TYPE_MESSAGE &&
0114 descriptor->message_type()->file()->name() == "google/protobuf/wrappers.proto";
0115 }
0116
0117 inline bool SupportsPresenceApi(const FieldDescriptor* descriptor) {
0118
0119
0120
0121
0122 if (descriptor->type() == FieldDescriptor::TYPE_MESSAGE) {
0123 return false;
0124 }
0125
0126 return descriptor->has_presence();
0127 }
0128
0129 inline bool RequiresPresenceBit(const FieldDescriptor* descriptor) {
0130 return SupportsPresenceApi(descriptor) &&
0131 !IsNullable(descriptor) &&
0132 !descriptor->is_extension() &&
0133 !descriptor->real_containing_oneof();
0134 }
0135
0136 }
0137 }
0138 }
0139 }
0140
0141 #include "google/protobuf/port_undef.inc"
0142
0143 #endif