public final class InternalNano
extends java.lang.Object
protobuf
package.
Others should not use this class directly.Modifier and Type | Field and Description |
---|---|
(package private) static java.nio.charset.Charset |
ISO_8859_1 |
static java.lang.Object |
LAZY_INIT_LOCK
An object to provide synchronization when lazily initializing static fields
of
MessageNano subclasses. |
static int |
TYPE_BOOL |
static int |
TYPE_BYTES |
static int |
TYPE_DOUBLE |
static int |
TYPE_ENUM |
static int |
TYPE_FIXED32 |
static int |
TYPE_FIXED64 |
static int |
TYPE_FLOAT |
static int |
TYPE_GROUP |
static int |
TYPE_INT32 |
static int |
TYPE_INT64 |
static int |
TYPE_MESSAGE |
static int |
TYPE_SFIXED32 |
static int |
TYPE_SFIXED64 |
static int |
TYPE_SINT32 |
static int |
TYPE_SINT64 |
static int |
TYPE_STRING |
static int |
TYPE_UINT32 |
static int |
TYPE_UINT64 |
(package private) static java.nio.charset.Charset |
UTF_8 |
Modifier | Constructor and Description |
---|---|
private |
InternalNano() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
bytesDefaultValue(java.lang.String bytes)
Helper called by generated code to construct default values for bytes
fields.
|
static void |
cloneUnknownFieldData(ExtendableMessageNano original,
ExtendableMessageNano cloned) |
static <K,V> int |
computeMapFieldSize(java.util.Map<K,V> map,
int number,
int keyType,
int valueType) |
static byte[] |
copyFromUtf8(java.lang.String text)
Helper function to convert a string into UTF-8 while turning the
UnsupportedEncodingException to a RuntimeException.
|
static boolean |
equals(boolean[] field1,
boolean[] field2)
Checks repeated boolean field equality; null-value and 0-length fields are
considered equal.
|
static boolean |
equals(byte[][] field1,
byte[][] field2)
Checks repeated bytes field equality.
|
static boolean |
equals(double[] field1,
double[] field2)
Checks repeated double field equality; null-value and 0-length fields are
considered equal.
|
static boolean |
equals(float[] field1,
float[] field2)
Checks repeated float field equality; null-value and 0-length fields are
considered equal.
|
static boolean |
equals(int[] field1,
int[] field2)
Checks repeated int field equality; null-value and 0-length fields are
considered equal.
|
static boolean |
equals(long[] field1,
long[] field2)
Checks repeated long field equality; null-value and 0-length fields are
considered equal.
|
static <K,V> boolean |
equals(java.util.Map<K,V> a,
java.util.Map<K,V> b)
Checks whether two
Map are equal. |
static boolean |
equals(java.lang.Object[] field1,
java.lang.Object[] field2)
Checks repeated string/message field equality.
|
private static boolean |
equalsMapValue(java.lang.Object a,
java.lang.Object b) |
static int |
hashCode(boolean[] field)
Computes the hash code of a repeated boolean field.
|
static int |
hashCode(byte[][] field)
Computes the hash code of a repeated bytes field.
|
static int |
hashCode(double[] field)
Computes the hash code of a repeated double field.
|
static int |
hashCode(float[] field)
Computes the hash code of a repeated float field.
|
static int |
hashCode(int[] field)
Computes the hash code of a repeated int field.
|
static int |
hashCode(long[] field)
Computes the hash code of a repeated long field.
|
static <K,V> int |
hashCode(java.util.Map<K,V> map) |
static int |
hashCode(java.lang.Object[] field)
Computes the hash code of a repeated string/message field.
|
private static int |
hashCodeForMap(java.lang.Object o) |
static <K,V> java.util.Map<K,V> |
mergeMapEntry(CodedInputByteBufferNano input,
java.util.Map<K,V> map,
MapFactories.MapFactory mapFactory,
int keyType,
int valueType,
V value,
int keyTag,
int valueTag)
Merges the map entry into the map field.
|
private static java.lang.Object |
primitiveDefaultValue(int type) |
static <K,V> void |
serializeMapField(CodedOutputByteBufferNano output,
java.util.Map<K,V> map,
int number,
int keyType,
int valueType) |
static java.lang.String |
stringDefaultValue(java.lang.String bytes)
Helper called by generated code to construct default values for string
fields.
|
public static final int TYPE_DOUBLE
public static final int TYPE_FLOAT
public static final int TYPE_INT64
public static final int TYPE_UINT64
public static final int TYPE_INT32
public static final int TYPE_FIXED64
public static final int TYPE_FIXED32
public static final int TYPE_BOOL
public static final int TYPE_STRING
public static final int TYPE_GROUP
public static final int TYPE_MESSAGE
public static final int TYPE_BYTES
public static final int TYPE_UINT32
public static final int TYPE_ENUM
public static final int TYPE_SFIXED32
public static final int TYPE_SFIXED64
public static final int TYPE_SINT32
public static final int TYPE_SINT64
static final java.nio.charset.Charset UTF_8
static final java.nio.charset.Charset ISO_8859_1
public static final java.lang.Object LAZY_INIT_LOCK
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.
public static java.lang.String stringDefaultValue(java.lang.String bytes)
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.
public static byte[] bytesDefaultValue(java.lang.String bytes)
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.
public static byte[] copyFromUtf8(java.lang.String text)
public static boolean equals(int[] field1, int[] field2)
public static boolean equals(long[] field1, long[] field2)
public static boolean equals(float[] field1, float[] field2)
public static boolean equals(double[] field1, double[] field2)
public static boolean equals(boolean[] field1, boolean[] field2)
public static boolean equals(byte[][] field1, byte[][] field2)
public static boolean equals(java.lang.Object[] field1, java.lang.Object[] field2)
public static int hashCode(int[] field)
public static int hashCode(long[] field)
public static int hashCode(float[] field)
public static int hashCode(double[] field)
public static int hashCode(boolean[] field)
public static int hashCode(byte[][] field)
public static int hashCode(java.lang.Object[] field)
private static java.lang.Object primitiveDefaultValue(int type)
public static final <K,V> java.util.Map<K,V> mergeMapEntry(CodedInputByteBufferNano input, java.util.Map<K,V> map, MapFactories.MapFactory mapFactory, int keyType, int valueType, V value, int keyTag, int valueTag) throws java.io.IOException
map
- the map field; may be null, in which case a map will be
instantiated using the MapFactories.MapFactory
input
- the input byte bufferkeyType
- key type, as defined in InternalNano.TYPE_*valueType
- value type, as defined in InternalNano.TYPE_*value
- an new instance of the value, if the value is a TYPE_MESSAGE;
otherwise this parameter can be null and will be ignored.keyTag
- wire tag for the keyvalueTag
- wire tag for the valuejava.io.IOException
public static <K,V> void serializeMapField(CodedOutputByteBufferNano output, java.util.Map<K,V> map, int number, int keyType, int valueType) throws java.io.IOException
java.io.IOException
public static <K,V> int computeMapFieldSize(java.util.Map<K,V> map, int number, int keyType, int valueType)
public static <K,V> boolean equals(java.util.Map<K,V> a, java.util.Map<K,V> b)
Map
are equal. We don't use the default equals
method of Map
because it compares by identity not by content for
byte arrays.private static boolean equalsMapValue(java.lang.Object a, java.lang.Object b)
public static <K,V> int hashCode(java.util.Map<K,V> map)
private static int hashCodeForMap(java.lang.Object o)
public static void cloneUnknownFieldData(ExtendableMessageNano original, ExtendableMessageNano cloned)