Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:11:58

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2008 Google Inc.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 // Author: kenton@google.com (Kenton Varda)
0009 //  Based on original Protocol Buffers design by
0010 //  Sanjay Ghemawat, Jeff Dean, and others.
0011 
0012 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_INTERNAL_HELPERS_H__
0013 #define GOOGLE_PROTOBUF_COMPILER_JAVA_INTERNAL_HELPERS_H__
0014 
0015 #include "google/protobuf/compiler/java/java_features.pb.h"
0016 #include "google/protobuf/compiler/java/generator.h"
0017 #include "google/protobuf/compiler/java/names.h"
0018 #include "google/protobuf/descriptor.h"
0019 #include "google/protobuf/descriptor.pb.h"
0020 
0021 // Must be last.
0022 #include "google/protobuf/port_def.inc"
0023 
0024 namespace google {
0025 namespace protobuf {
0026 namespace compiler {
0027 namespace java {
0028 
0029 // Whether unknown enum values are kept (i.e., not stored in UnknownFieldSet
0030 // but in the message and can be queried using additional getters that return
0031 // ints.
0032 inline bool SupportUnknownEnumValue(const FieldDescriptor* field) {
0033   if (JavaGenerator::GetResolvedSourceFeatures(*field)
0034           .GetExtension(pb::java)
0035           .legacy_closed_enum()) {
0036     return false;
0037   }
0038   return field->enum_type() != nullptr && !field->enum_type()->is_closed();
0039 }
0040 
0041 inline bool CheckUtf8(const FieldDescriptor* descriptor) {
0042   if (JavaGenerator::GetResolvedSourceFeatures(*descriptor)
0043           .GetExtension(pb::java)
0044           .utf8_validation() == pb::JavaFeatures::VERIFY) {
0045     return true;
0046   }
0047   return JavaGenerator::GetResolvedSourceFeatures(*descriptor)
0048                  .utf8_validation() == FeatureSet::VERIFY ||
0049          // For legacy syntax. This is not allowed under Editions.
0050          descriptor->file()->options().java_string_check_utf8();
0051 }
0052 
0053 
0054 // Only the lowest two bytes of the return value are used. The lowest byte
0055 // is the integer value of a j/c/g/protobuf/FieldType enum. For the other
0056 // byte:
0057 //    bit 0: whether the field is required.
0058 //    bit 1: whether the field requires UTF-8 validation.
0059 //    bit 2: whether the field needs isInitialized check.
0060 //    bit 3: whether the field is a closed enum.
0061 //    bits 4-7: unused
0062 int GetExperimentalJavaFieldType(const FieldDescriptor* field);
0063 
0064 }  // namespace java
0065 }  // namespace compiler
0066 }  // namespace protobuf
0067 }  // namespace google
0068 
0069 #include "google/protobuf/port_undef.inc"
0070 #endif  // GOOGLE_PROTOBUF_COMPILER_JAVA_INTERNAL_HELPERS_H__