Class Internal
protobuf package. Others should not use this class directly.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAListimplementation that avoids boxing the elements into Booleans if possible.static interfaceAListimplementation that avoids boxing the elements into Doubles if possible.static interfaceInterface for an enum value or value descriptor, to be used in FieldSet.static interfaceInternal.EnumLiteMap<T extends Internal.EnumLite>Interface for an object which maps integers toInternal.EnumLites.static interfaceInterface for an object which verifies integers are in range.static interfaceAListimplementation that avoids boxing the elements into Floats if possible.static interfaceAListimplementation that avoids boxing the elements into Integers if possible.static classProvides an immutable view ofList<T>around aList<F>.static interfaceAListimplementation that avoids boxing the elements into Longs if possible.static classWrap around aMap<K, RealValue>and provide aMap<K, V>interface.static interfaceExtendsListto add the capability to make the list immutable and inspect if it is modifiable. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intstatic final byte[]An empty byte array constant used in generated code.static final ByteBufferAn empty byte array constant used in generated code.static final CodedInputStreamAn empty coded input stream constant used in generated code.(package private) static final Charset(package private) static final Charset(package private) static final Charset -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]byteArrayDefaultValue(String bytes) Helper called by generated code to construct default values for bytes fields.static ByteBufferbyteBufferDefaultValue(String bytes) Helper called by generated code to construct default values for bytes fields.static ByteStringbytesDefaultValue(String bytes) Helper called by generated code to construct default values for bytes fields.(package private) static <T> TcheckNotNull(T obj) Throws an appropriateNullPointerExceptionif the given objects isnull.(package private) static <T> TcheckNotNull(T obj, String message) Throws an appropriateNullPointerExceptionif the given objects isnull.static ByteBuffercopyByteBuffer(ByteBuffer source) Create a new ByteBuffer and copy all the content ofsourceByteBuffer to the new ByteBuffer.static booleanHelper method for implementingMessage.equals(Object)for bytes field.static booleanHelper method for implementingMessage.equals(Object)for bytes field.static booleanequalsByteBuffer(List<ByteBuffer> a, List<ByteBuffer> b) Helper method for implementingMessage.equals(Object)for bytes field.static <T extends MessageLite>
TgetDefaultInstance(Class<T> clazz) static inthashBoolean(boolean b) Helper method for implementingMessage.hashCode()for booleans.static inthashCode(byte[] bytes) Helper method for implementingMessage.hashCode()for bytes field.(package private) static inthashCode(byte[] bytes, int offset, int length) Helper method for implementingLiteralByteString#hashCode().static intHelper method for implementingMessage.hashCode()for bytes field.static inthashCodeByteBuffer(ByteBuffer bytes) Helper method for implementingMessage.hashCode()for bytes field.static inthashCodeByteBuffer(List<ByteBuffer> list) Helper method for implementingMessage.hashCode()for bytes field.static intHelper method for implementingMessage.hashCode()for enums.static inthashEnumList(List<? extends Internal.EnumLite> list) Helper method for implementingMessage.hashCode()for enum lists.static inthashLong(long n) Helper method for implementingMessage.hashCode()for longs.static booleanisValidUtf8(byte[] byteArray) LikeisValidUtf8(ByteString)but for byte arrays.static booleanisValidUtf8(ByteString byteString) Helper called by generated code to determine if a byte array is a valid UTF-8 encoded string such that the original bytes can be converted to a String object and then back to a byte array round tripping the bytes without loss.(package private) static ObjectmergeMessage(Object destination, Object source) Helper method to merge two MessageLite instances.(package private) static intpartialHash(int h, byte[] bytes, int offset, int length) Helper method for continuously hashing bytes.static StringstringDefaultValue(String bytes) Helper called by generated code to construct default values for string fields.static byte[]toByteArray(String value) Helper method to get the UTF-8 bytes of a string.static StringtoStringUtf8(byte[] bytes) Helper method to convert a byte array to a string using UTF-8 encoding.
-
Field Details
-
US_ASCII
-
UTF_8
-
ISO_8859_1
-
DEFAULT_BUFFER_SIZE
private static final int DEFAULT_BUFFER_SIZE- See Also:
-
EMPTY_BYTE_ARRAY
public static final byte[] EMPTY_BYTE_ARRAYAn empty byte array constant used in generated code. -
EMPTY_BYTE_BUFFER
An empty byte array constant used in generated code. -
EMPTY_CODED_INPUT_STREAM
An empty coded input stream constant used in generated code.
-
-
Constructor Details
-
Internal
private Internal()
-
-
Method Details
-
checkNotNull
static <T> T checkNotNull(T obj) Throws an appropriateNullPointerExceptionif the given objects isnull. -
checkNotNull
Throws an appropriateNullPointerExceptionif the given objects isnull. -
stringDefaultValue
Helper called by generated code to construct default values for string fields.The protocol compiler does not actually contain a UTF-8 decoder -- it just pushes UTF-8-encoded text around without touching it. The one place where this presents a problem is when generating Java string literals. Unicode characters in the string literal would normally need to be encoded using a Unicode escape sequence, which would require decoding them. To get around this, protoc instead embeds the UTF-8 bytes into the generated code and leaves it to the runtime library to decode them.
It gets worse, though. If protoc just generated a byte array, like: new byte[] {0x12, 0x34, 0x56, 0x78} Java actually generates *code* which allocates an array and then fills in each value. This is much less efficient than just embedding the bytes directly into the bytecode. To get around this, we need another work-around. String literals are embedded directly, so protoc actually generates a string literal corresponding to the bytes. The easiest way to do this is to use the ISO-8859-1 character set, which corresponds to the first 256 characters of the Unicode range. Protoc can then use good old CEscape to generate the string.
So we have a string literal which represents a set of bytes which represents another string. This function -- stringDefaultValue -- converts from the generated string to the string we actually want. The generated code calls this automatically.
-
bytesDefaultValue
Helper called by generated code to construct default values for bytes fields.This is a lot like
stringDefaultValue(java.lang.String), but for bytes fields. In this case we only need the second of the two hacks -- allowing us to embed raw bytes as a string literal with ISO-8859-1 encoding. -
byteArrayDefaultValue
Helper called by generated code to construct default values for bytes fields.This is like
bytesDefaultValue(java.lang.String), but returns a byte array. -
byteBufferDefaultValue
Helper called by generated code to construct default values for bytes fields.This is like
bytesDefaultValue(java.lang.String), but returns a ByteBuffer. -
copyByteBuffer
Create a new ByteBuffer and copy all the content ofsourceByteBuffer to the new ByteBuffer. The new ByteBuffer's limit and capacity will be source.capacity(), and its position will be 0. Note that the state ofsourceByteBuffer won't be changed. -
isValidUtf8
Helper called by generated code to determine if a byte array is a valid UTF-8 encoded string such that the original bytes can be converted to a String object and then back to a byte array round tripping the bytes without loss. More precisely, returnstruewhenever:Arrays.equals(byteString.toByteArray(), new String(byteString.toByteArray(), "UTF-8").getBytes("UTF-8"))This method rejects "overlong" byte sequences, as well as 3-byte sequences that would map to a surrogate character, in accordance with the restricted definition of UTF-8 introduced in Unicode 3.1. Note that the UTF-8 decoder included in Oracle's JDK has been modified to also reject "overlong" byte sequences, but currently (2011) still accepts 3-byte surrogate character byte sequences.
See the Unicode Standard,
Table 3-6. UTF-8 Bit Distribution,
Table 3-7. Well Formed UTF-8 Byte Sequences.As of 2011-02, this method simply returns the result of
ByteString.isValidUtf8(). Calling that method directly is preferred.- Parameters:
byteString- the string to check- Returns:
- whether the byte array is round trippable
-
isValidUtf8
public static boolean isValidUtf8(byte[] byteArray) LikeisValidUtf8(ByteString)but for byte arrays. -
toByteArray
Helper method to get the UTF-8 bytes of a string. -
toStringUtf8
Helper method to convert a byte array to a string using UTF-8 encoding. -
hashLong
public static int hashLong(long n) Helper method for implementingMessage.hashCode()for longs.- See Also:
-
hashBoolean
public static int hashBoolean(boolean b) Helper method for implementingMessage.hashCode()for booleans.- See Also:
-
hashEnum
Helper method for implementingMessage.hashCode()for enums.This is needed because
Enum.hashCode()is final, but we need to use the field number as the hash code to ensure compatibility between statically and dynamically generated enum objects. -
hashEnumList
Helper method for implementingMessage.hashCode()for enum lists. -
equals
Helper method for implementingMessage.equals(Object)for bytes field. -
hashCode
Helper method for implementingMessage.hashCode()for bytes field. -
hashCode
public static int hashCode(byte[] bytes) Helper method for implementingMessage.hashCode()for bytes field. -
hashCode
static int hashCode(byte[] bytes, int offset, int length) Helper method for implementingLiteralByteString#hashCode(). -
partialHash
static int partialHash(int h, byte[] bytes, int offset, int length) Helper method for continuously hashing bytes. -
equalsByteBuffer
Helper method for implementingMessage.equals(Object)for bytes field. -
equalsByteBuffer
Helper method for implementingMessage.equals(Object)for bytes field. -
hashCodeByteBuffer
Helper method for implementingMessage.hashCode()for bytes field. -
hashCodeByteBuffer
Helper method for implementingMessage.hashCode()for bytes field. -
getDefaultInstance
-
mergeMessage
Helper method to merge two MessageLite instances.
-