UnknownFieldSchema.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 java.io.IOException;
34 
35 @ExperimentalApi
36 abstract class UnknownFieldSchema<T, B> {
37 
39  abstract boolean shouldDiscardUnknownFields(Reader reader);
40 
42  abstract void addVarint(B fields, int number, long value);
43 
45  abstract void addFixed32(B fields, int number, int value);
46 
48  abstract void addFixed64(B fields, int number, long value);
49 
51  abstract void addLengthDelimited(B fields, int number, ByteString value);
52 
54  abstract void addGroup(B fields, int number, T subFieldSet);
55 
57  abstract B newBuilder();
58 
60  abstract T toImmutable(B fields);
61 
66  abstract void setToMessage(Object message, T fields);
67 
69  abstract T getFromMessage(Object message);
70 
72  abstract B getBuilderFromMessage(Object message);
73 
75  abstract void setBuilderToMessage(Object message, B builder);
76 
78  abstract void makeImmutable(Object message);
79 
81  final boolean mergeOneFieldFrom(B unknownFields, Reader reader) throws IOException {
82  int tag = reader.getTag();
83  int fieldNumber = WireFormat.getTagFieldNumber(tag);
84  switch (WireFormat.getTagWireType(tag)) {
85  case WireFormat.WIRETYPE_VARINT:
86  addVarint(unknownFields, fieldNumber, reader.readInt64());
87  return true;
88  case WireFormat.WIRETYPE_FIXED32:
89  addFixed32(unknownFields, fieldNumber, reader.readFixed32());
90  return true;
91  case WireFormat.WIRETYPE_FIXED64:
92  addFixed64(unknownFields, fieldNumber, reader.readFixed64());
93  return true;
94  case WireFormat.WIRETYPE_LENGTH_DELIMITED:
95  addLengthDelimited(unknownFields, fieldNumber, reader.readBytes());
96  return true;
97  case WireFormat.WIRETYPE_START_GROUP:
98  final B subFields = newBuilder();
99  int endGroupTag = WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP);
100  mergeFrom(subFields, reader);
101  if (endGroupTag != reader.getTag()) {
102  throw InvalidProtocolBufferException.invalidEndTag();
103  }
104  addGroup(unknownFields, fieldNumber, toImmutable(subFields));
105  return true;
106  case WireFormat.WIRETYPE_END_GROUP:
107  return false;
108  default:
109  throw InvalidProtocolBufferException.invalidWireType();
110  }
111  }
112 
113  final void mergeFrom(B unknownFields, Reader reader) throws IOException {
114  while (true) {
115  if (reader.getFieldNumber() == Reader.READ_DONE
116  || !mergeOneFieldFrom(unknownFields, reader)) {
117  break;
118  }
119  }
120  }
121 
122  abstract void writeTo(T unknownFields, Writer writer) throws IOException;
123 
124  abstract void writeAsMessageSetTo(T unknownFields, Writer writer) throws IOException;
125 
127  abstract T merge(T destination, T source);
128 
130  abstract int getSerializedSizeAsMessageSet(T message);
131 
132  abstract int getSerializedSize(T unknowns);
133 }
T
#define T(upbtypeconst, upbtype, ctype, default_value)
merge
static void merge(upb_refcounted *r, upb_refcounted *from)
Definition: ruby/ext/google/protobuf_c/upb.c:6188
source
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:3072
java
fields
static const upb_fielddef fields[107]
Definition: ruby/ext/google/protobuf_c/upb.c:7671
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
number
double number
Definition: cJSON.h:326
message
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glcorearb.h:2695


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:07:00