StructuralMessageInfo.java
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 package com.google.protobuf;
32 
33 import static com.google.protobuf.Internal.checkNotNull;
34 
35 import java.util.ArrayList;
36 import java.util.Collections;
37 import java.util.List;
38 
43 @ExperimentalApi
44 final class StructuralMessageInfo implements MessageInfo {
45  private final ProtoSyntax syntax;
46  private final boolean messageSetWireFormat;
47  private final int[] checkInitialized;
48  private final FieldInfo[] fields;
49  private final MessageLite defaultInstance;
50 
57  StructuralMessageInfo(
58  ProtoSyntax syntax,
59  boolean messageSetWireFormat,
60  int[] checkInitialized,
61  FieldInfo[] fields,
62  Object defaultInstance) {
63  this.syntax = syntax;
64  this.messageSetWireFormat = messageSetWireFormat;
65  this.checkInitialized = checkInitialized;
66  this.fields = fields;
67  this.defaultInstance = (MessageLite) checkNotNull(defaultInstance, "defaultInstance");
68  }
69 
71  @Override
72  public ProtoSyntax getSyntax() {
73  return syntax;
74  }
75 
77  @Override
78  public boolean isMessageSetWireFormat() {
79  return messageSetWireFormat;
80  }
81 
83  public int[] getCheckInitialized() {
84  return checkInitialized;
85  }
86 
91  public FieldInfo[] getFields() {
92  return fields;
93  }
94 
95  @Override
96  public MessageLite getDefaultInstance() {
97  return defaultInstance;
98  }
99 
101  public static Builder newBuilder() {
102  return new Builder();
103  }
104 
106  public static Builder newBuilder(int numFields) {
107  return new Builder(numFields);
108  }
109 
111  public static final class Builder {
112  private final List<FieldInfo> fields;
114  private boolean wasBuilt;
115  private boolean messageSetWireFormat;
116  private int[] checkInitialized = null;
117  private Object defaultInstance;
118 
119  public Builder() {
120  fields = new ArrayList<FieldInfo>();
121  }
122 
123  public Builder(int numFields) {
124  fields = new ArrayList<FieldInfo>(numFields);
125  }
126 
127  public void withDefaultInstance(Object defaultInstance) {
128  this.defaultInstance = defaultInstance;
129  }
130 
132  this.syntax = checkNotNull(syntax, "syntax");
133  }
134 
136  this.messageSetWireFormat = messageSetWireFormat;
137  }
138 
140  this.checkInitialized = checkInitialized;
141  }
142 
143  public void withField(FieldInfo field) {
144  if (wasBuilt) {
145  throw new IllegalStateException("Builder can only build once");
146  }
147  fields.add(field);
148  }
149 
150  public StructuralMessageInfo build() {
151  if (wasBuilt) {
152  throw new IllegalStateException("Builder can only build once");
153  }
154  if (syntax == null) {
155  throw new IllegalStateException("Must specify a proto syntax");
156  }
157  wasBuilt = true;
158  Collections.sort(fields);
159  return new StructuralMessageInfo(
160  syntax,
163  fields.toArray(new FieldInfo[0]),
165  }
166  }
167 }
com.google.protobuf.StructuralMessageInfo.Builder.withMessageSetWireFormat
void withMessageSetWireFormat(boolean messageSetWireFormat)
Definition: StructuralMessageInfo.java:135
com.google.protobuf.StructuralMessageInfo.Builder.Builder
Builder(int numFields)
Definition: StructuralMessageInfo.java:123
com.google.protobuf.StructuralMessageInfo.Builder.fields
final List< FieldInfo > fields
Definition: StructuralMessageInfo.java:112
com.google.protobuf.StructuralMessageInfo.Builder.withDefaultInstance
void withDefaultInstance(Object defaultInstance)
Definition: StructuralMessageInfo.java:127
com.google.protobuf
Definition: ProtoCaliperBenchmark.java:2
com.google.protobuf.StructuralMessageInfo.Builder.withSyntax
void withSyntax(ProtoSyntax syntax)
Definition: StructuralMessageInfo.java:131
com.google.protobuf.StructuralMessageInfo.Builder.withField
void withField(FieldInfo field)
Definition: StructuralMessageInfo.java:143
com.google.protobuf.StructuralMessageInfo.Builder.wasBuilt
boolean wasBuilt
Definition: StructuralMessageInfo.java:114
com.google.protobuf.StructuralMessageInfo.Builder.defaultInstance
Object defaultInstance
Definition: StructuralMessageInfo.java:117
com.google.protobuf.StructuralMessageInfo.Builder.messageSetWireFormat
boolean messageSetWireFormat
Definition: StructuralMessageInfo.java:115
field
const FieldDescriptor * field
Definition: parser_unittest.cc:2694
com.google.protobuf.StructuralMessageInfo.Builder
Definition: StructuralMessageInfo.java:111
com.google.protobuf.StructuralMessageInfo.Builder.Builder
Builder()
Definition: StructuralMessageInfo.java:119
Builder
Definition: ruby/ext/google/protobuf_c/protobuf.h:162
java
fields
static const upb_fielddef fields[107]
Definition: ruby/ext/google/protobuf_c/upb.c:7671
com.google.protobuf.StructuralMessageInfo.Builder.checkInitialized
int[] checkInitialized
Definition: StructuralMessageInfo.java:116
com.google.protobuf.StructuralMessageInfo.Builder.withCheckInitialized
void withCheckInitialized(int[] checkInitialized)
Definition: StructuralMessageInfo.java:139
com.google
com
com.google.protobuf.Internal
Definition: Internal.java:54
com.google.protobuf.ProtoSyntax
Definition: ProtoSyntax.java:35
com.google.protobuf.StructuralMessageInfo.Builder.syntax
ProtoSyntax syntax
Definition: StructuralMessageInfo.java:113
com.google.protobuf.StructuralMessageInfo.Builder.build
StructuralMessageInfo build()
Definition: StructuralMessageInfo.java:150
Builder
struct Builder Builder
Definition: ruby/ext/google/protobuf_c/protobuf.h:67


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