31 package com.google.protobuf;
33 import java.io.IOException;
49 static final int FIXED32_SIZE = 4;
50 static final int FIXED64_SIZE = 8;
51 static final int MAX_VARINT32_SIZE = 5;
52 static final int MAX_VARINT64_SIZE = 10;
53 static final int MAX_VARINT_SIZE = 10;
62 static final int TAG_TYPE_BITS = 3;
63 static final int TAG_TYPE_MASK = (1 << TAG_TYPE_BITS) - 1;
67 return tag & TAG_TYPE_MASK;
72 return tag >>> TAG_TYPE_BITS;
76 static int makeTag(
final int fieldNumber,
final int wireType) {
77 return (fieldNumber << TAG_TYPE_BITS) | wireType;
96 this.defaultDefault = defaultDefault;
101 return defaultDefault;
122 public boolean isPackable() {
128 public boolean isPackable() {
134 public boolean isPackable() {
140 public boolean isPackable() {
152 this.javaType = javaType;
153 this.wireType = wireType;
173 static final int MESSAGE_SET_ITEM = 1;
174 static final int MESSAGE_SET_TYPE_ID = 2;
175 static final int MESSAGE_SET_MESSAGE = 3;
179 static final int MESSAGE_SET_ITEM_END_TAG = makeTag(MESSAGE_SET_ITEM,
WIRETYPE_END_GROUP);
180 static final int MESSAGE_SET_TYPE_ID_TAG = makeTag(MESSAGE_SET_TYPE_ID,
WIRETYPE_VARINT);
181 static final int MESSAGE_SET_MESSAGE_TAG =
188 enum Utf8Validation {
193 return input.readString();
199 Object readString(CodedInputStream
input)
throws IOException {
200 return input.readStringRequireUtf8();
206 Object readString(CodedInputStream
input)
throws IOException {
207 return input.readBytes();
212 abstract Object readString(CodedInputStream
input)
throws IOException;
225 static Object readPrimitiveField(
226 CodedInputStream
input,
FieldType type, Utf8Validation utf8Validation)
throws IOException {
229 return input.readDouble();
231 return input.readFloat();
233 return input.readInt64();
235 return input.readUInt64();
237 return input.readInt32();
239 return input.readFixed64();
241 return input.readFixed32();
243 return input.readBool();
245 return input.readBytes();
247 return input.readUInt32();
249 return input.readSFixed32();
251 return input.readSFixed64();
253 return input.readSInt32();
255 return input.readSInt64();
258 return utf8Validation.readString(
input);
260 throw new IllegalArgumentException(
"readPrimitiveField() cannot handle nested groups.");
262 throw new IllegalArgumentException(
"readPrimitiveField() cannot handle embedded messages.");
266 throw new IllegalArgumentException(
"readPrimitiveField() cannot handle enums.");
269 throw new RuntimeException(
"There is no way to get here, but the compiler thinks otherwise.");