• 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 // Author: kenton@google.com (Kenton Varda)
9 //  Based on original Protocol Buffers design by
10 //  Sanjay Ghemawat, Jeff Dean, and others.
11 
12 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_INTERNAL_HELPERS_H__
13 #define GOOGLE_PROTOBUF_COMPILER_JAVA_INTERNAL_HELPERS_H__
14 
15 #include "google/protobuf/compiler/java/java_features.pb.h"
16 #include "google/protobuf/compiler/java/context.h"
17 #include "google/protobuf/compiler/java/generator.h"
18 #include "google/protobuf/compiler/java/name_resolver.h"
19 #include "google/protobuf/compiler/java/names.h"
20 #include "google/protobuf/descriptor.h"
21 #include "google/protobuf/descriptor.pb.h"
22 
23 // Must be last.
24 #include "google/protobuf/port_def.inc"
25 
26 namespace google {
27 namespace protobuf {
28 namespace compiler {
29 namespace java {
30 
31 // Whether unknown enum values are kept (i.e., not stored in UnknownFieldSet
32 // but in the message and can be queried using additional getters that return
33 // ints.
SupportUnknownEnumValue(const FieldDescriptor * field)34 inline bool SupportUnknownEnumValue(const FieldDescriptor* field) {
35   if (JavaGenerator::GetResolvedSourceFeatures(*field)
36           .GetExtension(pb::java)
37           .legacy_closed_enum()) {
38     return false;
39   }
40   return field->enum_type() != nullptr && !field->enum_type()->is_closed();
41 }
42 
CheckUtf8(const FieldDescriptor * descriptor)43 inline bool CheckUtf8(const FieldDescriptor* descriptor) {
44   if (JavaGenerator::GetResolvedSourceFeatures(*descriptor)
45           .GetExtension(pb::java)
46           .utf8_validation() == pb::JavaFeatures::VERIFY) {
47     return true;
48   }
49   return JavaGenerator::GetResolvedSourceFeatures(*descriptor)
50                  .utf8_validation() == FeatureSet::VERIFY ||
51          // For legacy syntax. This is not allowed under Editions.
52          descriptor->file()->options().java_string_check_utf8();
53 }
54 
55 
56 // Only the lowest two bytes of the return value are used. The lowest byte
57 // is the integer value of a j/c/g/protobuf/FieldType enum. For the other
58 // byte:
59 //    bit 0: whether the field is required.
60 //    bit 1: whether the field requires UTF-8 validation.
61 //    bit 2: whether the field needs isInitialized check.
62 //    bit 3: whether the field is a closed enum.
63 //    bits 4-7: unused
64 int GetExperimentalJavaFieldType(const FieldDescriptor* field);
65 
66 }  // namespace java
67 }  // namespace compiler
68 }  // namespace protobuf
69 }  // namespace google
70 
71 #include "google/protobuf/port_undef.inc"
72 #endif  // GOOGLE_PROTOBUF_COMPILER_JAVA_INTERNAL_HELPERS_H__
73