Class Utf8.MobileProcessor
java.lang.Object
com.google.protobuf.Utf8.Processor
com.google.protobuf.Utf8.MobileProcessor
- Enclosing class:
Utf8
Utf8.Processor optimized for mobile platforms.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) StringdecodeUtf8(byte[] bytes, int index, int size) Decodes the given byte array slice into aString.(package private) intencodeUtf8(String in, byte[] out, int offset, int length) Encodes an input character sequence (in) to UTF-8 in the target array (out).protected voidencodeUtf8Internal(String in, ByteBuffer out) Encodes the input character sequence to a directByteBufferinstance.Methods inherited from class Utf8.Processor
decodeUtf8, decodeUtf8NonArrayByteBuffer, encodedLength, encodeUtf8, encodeUtf8Naive, encodeUtf8Naive
-
Constructor Details
-
MobileProcessor
MobileProcessor()
-
-
Method Details
-
decodeUtf8
Description copied from class:Utf8.ProcessorDecodes the given byte array slice into aString.- Specified by:
decodeUtf8in classUtf8.Processor- Throws:
InvalidProtocolBufferException- if the byte array slice is not valid UTF-8
-
encodeUtf8
Description copied from class:Utf8.ProcessorEncodes an input character sequence (in) to UTF-8 in the target array (out). For a string, this method is functionally identical to
but may be implemented differently for efficiency purposes.byte[] a = string.getBytes(UTF_8); System.arraycopy(a, 0, bytes, offset, a.length); return offset + a.length;Matching
String.getBytes(UTF_8)this replaces unpaired surrogates with a replacement character.To ensure sufficient space in the output buffer, either call
Utf8.Processor.encodedLength(String)to compute the exact amount needed, or leave room forUtf8.MAX_BYTES_PER_CHAR * sequence.length(), which is the largest possible number of bytes that any input can be encoded to.- Specified by:
encodeUtf8in classUtf8.Processor- Parameters:
in- the input character sequence to be encodedout- the target arrayoffset- the starting offset inbytesto start writing atlength- the length of thebytes, starting fromoffset- Returns:
- the new offset, equivalent to
offset + Utf8.encodedLength(sequence)
-
encodeUtf8Internal
Description copied from class:Utf8.ProcessorEncodes the input character sequence to a directByteBufferinstance.- Specified by:
encodeUtf8Internalin classUtf8.Processor
-