Top Description Fields Constructors Methods
com.google.protobuf.nano

public final Class InternalNano

extends Object
Class Inheritance
Imports
com.google.protobuf.nano.MapFactories.MapFactory, java.io.IOException, java.nio.charset.Charset, java.util.Arrays, .Map, .Map.Entry

The classes contained within are used internally by the Protocol Buffer library and generated message implementations. They are public only because those generated messages do not reside in the protobuf package. Others should not use this class directly.
Author
[email protected] (Kenton Varda)

Field Summary

Modifier and TypeField and Description
protected static final Charset
public static final Object
LAZY_INIT_LOCK

An object to provide synchronization when lazily initializing static fields of MessageNano subclasses.

public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
protected static final Charset

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static byte[]
bytesDefaultValue(String bytes)

Helper called by generated code to construct default values for bytes fields.

public static void
public static <K, V> int
computeMapFieldSize(Map<K, V> map, int number, int keyType, int valueType)

public static byte[]
copyFromUtf8(final String text)

Helper function to convert a string into UTF-8 while turning the UnsupportedEncodingException to a RuntimeException.

public static boolean
equals(int[] field1, int[] field2)

Checks repeated int field equality; null-value and 0-length fields are considered equal.

public static boolean
equals(long[] field1, long[] field2)

Checks repeated long field equality; null-value and 0-length fields are considered equal.

public static boolean
equals(float[] field1, float[] field2)

Checks repeated float field equality; null-value and 0-length fields are considered equal.

public static boolean
equals(double[] field1, double[] field2)

Checks repeated double field equality; null-value and 0-length fields are considered equal.

public static boolean
equals(boolean[] field1, boolean[] field2)

Checks repeated boolean field equality; null-value and 0-length fields are considered equal.

public static boolean
equals(byte[][] field1, byte[][] field2)

Checks repeated bytes field equality.

public static boolean
equals(Object[] field1, Object[] field2)

Checks repeated string/message field equality.

public static <K, V> boolean
equals(Map<K, V> a, Map<K, V> b)

Checks whether two Map are equal.

private static boolean
public static int
hashCode(int[] field)

Computes the hash code of a repeated int field.

public static int
hashCode(long[] field)

Computes the hash code of a repeated long field.

public static int
hashCode(float[] field)

Computes the hash code of a repeated float field.

public static int
hashCode(double[] field)

Computes the hash code of a repeated double field.

public static int
hashCode(boolean[] field)

Computes the hash code of a repeated boolean field.

public static int
hashCode(byte[][] field)

Computes the hash code of a repeated bytes field.

public static int
hashCode(Object[] field)

Computes the hash code of a repeated string/message field.

public static <K, V> int
hashCode(Map<K, V> map)

private static int
public static final <K, V> Map<K, V>

Returns:

the map field
mergeMapEntry
(CodedInputByteBufferNano
the input byte buffer
input
,
Map<K, V>
the map field; may be null, in which case a map will be instantiated using the MapFactories.MapFactory
map
,
MapFactories.MapFactory mapFactory, int
key type, as defined in InternalNano.TYPE_*
keyType
,
int
value type, as defined in InternalNano.TYPE_*
valueType
,
V
an new instance of the value, if the value is a TYPE_MESSAGE; otherwise this parameter can be null and will be ignored.
value
,
int
wire tag for the key
keyTag
,
int
wire tag for the value
valueTag
)

Merges the map entry into the map field.

private static Object
public static <K, V> void
serializeMapField(CodedOutputByteBufferNano output, Map<K, V> map, int number, int keyType, int valueType)

public static String
stringDefaultValue(String bytes)

Helper called by generated code to construct default values for string fields.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ISO_8859_1back to summary
protected static final Charset ISO_8859_1
LAZY_INIT_LOCKback to summary
public static final Object LAZY_INIT_LOCK

An object to provide synchronization when lazily initializing static fields of MessageNano subclasses.

To enable earlier versions of ProGuard to inline short methods from a generated MessageNano subclass to the call sites, that class must not have a class initializer, which will be created if there is any static variable initializers. To lazily initialize the static variables in a thread-safe manner, the initialization code will synchronize on this object.

TYPE_BOOLback to summary
public static final int TYPE_BOOL
TYPE_BYTESback to summary
public static final int TYPE_BYTES
TYPE_DOUBLEback to summary
public static final int TYPE_DOUBLE
TYPE_ENUMback to summary
public static final int TYPE_ENUM
TYPE_FIXED32back to summary
public static final int TYPE_FIXED32
TYPE_FIXED64back to summary
public static final int TYPE_FIXED64
TYPE_FLOATback to summary
public static final int TYPE_FLOAT
TYPE_GROUPback to summary
public static final int TYPE_GROUP
TYPE_INT32back to summary
public static final int TYPE_INT32
TYPE_INT64back to summary
public static final int TYPE_INT64
TYPE_MESSAGEback to summary
public static final int TYPE_MESSAGE
TYPE_SFIXED32back to summary
public static final int TYPE_SFIXED32
TYPE_SFIXED64back to summary
public static final int TYPE_SFIXED64
TYPE_SINT32back to summary
public static final int TYPE_SINT32
TYPE_SINT64back to summary
public static final int TYPE_SINT64
TYPE_STRINGback to summary
public static final int TYPE_STRING
TYPE_UINT32back to summary
public static final int TYPE_UINT32
TYPE_UINT64back to summary
public static final int TYPE_UINT64
UTF_8back to summary
protected static final Charset UTF_8

Constructor Detail

InternalNanoback to summary
private InternalNano()

Method Detail

bytesDefaultValueback to summary
public static byte[] bytesDefaultValue(String bytes)

Helper called by generated code to construct default values for bytes fields.

This is a lot like stringDefaultValue, 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.

cloneUnknownFieldDataback to summary
public static void cloneUnknownFieldData(ExtendableMessageNano<M extends ExtendableMessageNano<M>> original, ExtendableMessageNano<M extends ExtendableMessageNano<M>> cloned)
computeMapFieldSizeback to summary
public static <K, V> int computeMapFieldSize(Map<K, V> map, int number, int keyType, int valueType)
copyFromUtf8back to summary
public static byte[] copyFromUtf8(final String text)

Helper function to convert a string into UTF-8 while turning the UnsupportedEncodingException to a RuntimeException.

equalsback to summary
public static boolean equals(int[] field1, int[] field2)

Checks repeated int field equality; null-value and 0-length fields are considered equal.

equalsback to summary
public static boolean equals(long[] field1, long[] field2)

Checks repeated long field equality; null-value and 0-length fields are considered equal.

equalsback to summary
public static boolean equals(float[] field1, float[] field2)

Checks repeated float field equality; null-value and 0-length fields are considered equal.

equalsback to summary
public static boolean equals(double[] field1, double[] field2)

Checks repeated double field equality; null-value and 0-length fields are considered equal.

equalsback to summary
public static boolean equals(boolean[] field1, boolean[] field2)

Checks repeated boolean field equality; null-value and 0-length fields are considered equal.

equalsback to summary
public static boolean equals(byte[][] field1, byte[][] field2)

Checks repeated bytes field equality. Only non-null elements are tested. Returns true if the two fields have the same sequence of non-null elements. Null-value fields and fields of any length with only null elements are considered equal.

equalsback to summary
public static boolean equals(Object[] field1, Object[] field2)

Checks repeated string/message field equality. Only non-null elements are tested. Returns true if the two fields have the same sequence of non-null elements. Null-value fields and fields of any length with only null elements are considered equal.

equalsback to summary
public static <K, V> boolean equals(Map<K, V> a, Map<K, V> b)

Checks whether two Map are equal. We don't use the default equals method of Map because it compares by identity not by content for byte arrays.

equalsMapValueback to summary
private static boolean equalsMapValue(Object a, Object b)
hashCodeback to summary
public static int hashCode(int[] field)

Computes the hash code of a repeated int field. Null-value and 0-length fields have the same hash code.

hashCodeback to summary
public static int hashCode(long[] field)

Computes the hash code of a repeated long field. Null-value and 0-length fields have the same hash code.

hashCodeback to summary
public static int hashCode(float[] field)

Computes the hash code of a repeated float field. Null-value and 0-length fields have the same hash code.

hashCodeback to summary
public static int hashCode(double[] field)

Computes the hash code of a repeated double field. Null-value and 0-length fields have the same hash code.

hashCodeback to summary
public static int hashCode(boolean[] field)

Computes the hash code of a repeated boolean field. Null-value and 0-length fields have the same hash code.

hashCodeback to summary
public static int hashCode(byte[][] field)

Computes the hash code of a repeated bytes field. Only the sequence of all non-null elements are used in the computation. Null-value fields and fields of any length with only null elements have the same hash code.

hashCodeback to summary
public static int hashCode(Object[] field)

Computes the hash code of a repeated string/message field. Only the sequence of all non-null elements are used in the computation. Null-value fields and fields of any length with only null elements have the same hash code.

hashCodeback to summary
public static <K, V> int hashCode(Map<K, V> map)
hashCodeForMapback to summary
private static int hashCodeForMap(Object o)
mergeMapEntryback to summary
public static final <K, V> Map<K, V> mergeMapEntry(CodedInputByteBufferNano input, Map<K, V> map, MapFactories.MapFactory mapFactory, int keyType, int valueType, V value, int keyTag, int valueTag) throws IOException

Merges the map entry into the map field. Note this is only supposed to be called by generated messages.

Parameters
input:CodedInputByteBufferNano

the input byte buffer

map:Map<K, V>

the map field; may be null, in which case a map will be instantiated using the MapFactories.MapFactory

keyType:int

key type, as defined in InternalNano.TYPE_*

valueType:int

value type, as defined in InternalNano.TYPE_*

value:V

an new instance of the value, if the value is a TYPE_MESSAGE; otherwise this parameter can be null and will be ignored.

keyTag:int

wire tag for the key

valueTag:int

wire tag for the value

Returns:Map<K, V>

the map field

Annotations
@SuppressWarnings:unchecked
primitiveDefaultValueback to summary
private static Object primitiveDefaultValue(int type)
serializeMapFieldback to summary
public static <K, V> void serializeMapField(CodedOutputByteBufferNano output, Map<K, V> map, int number, int keyType, int valueType) throws IOException
stringDefaultValueback to summary
public static String stringDefaultValue(String bytes)

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.