Package io.protostuff
Class StringSerializer
- java.lang.Object
-
- io.protostuff.StringSerializer
-
public final class StringSerializer extends java.lang.Object
UTF-8 String serialization
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
StringSerializer.STRING
-
Field Summary
Fields Modifier and Type Field Description (package private) static char[]
DigitOnes
(package private) static char[]
digits
(package private) static char[]
DigitTens
(package private) static int
FIVE_BYTE_LOWER_LIMIT
(package private) static int
FOUR_BYTE_EXCLUSIVE
(package private) static int
FOUR_BYTE_LOWER_LIMIT
(package private) static byte[]
INT_MIN_VALUE
(package private) static byte[]
LONG_MIN_VALUE
(package private) static int
ONE_BYTE_EXCLUSIVE
(package private) static int[]
sizeTable
FromInteger.toString(int)
(package private) static int
THREE_BYTE_EXCLUSIVE
(package private) static int
THREE_BYTE_LOWER_LIMIT
(package private) static int
TWO_BYTE_EXCLUSIVE
(package private) static int
TWO_BYTE_LOWER_LIMIT
-
Constructor Summary
Constructors Modifier Constructor Description private
StringSerializer()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
computeUTF8Size(java.lang.CharSequence str, int index, int len)
Computes the size of the utf8 string beginning at the specifiedindex
with the specifiedlength
.static char
highSurrogate(int codePoint)
static char
lowSurrogate(int codePoint)
(package private) static void
putBytesFromInt(int i, int offset, int size, byte[] buf)
(package private) static void
putBytesFromLong(long i, int offset, int size, byte[] buf)
(package private) static int
stringSize(int x)
(package private) static int
stringSize(long x)
static LinkedBuffer
writeAscii(java.lang.CharSequence str, WriteSession session, LinkedBuffer lb)
Writes the ascii bytes from the string into theLinkedBuffer
.static LinkedBuffer
writeDouble(double value, WriteSession session, LinkedBuffer lb)
Writes the stringified double into theLinkedBuffer
.(package private) static void
writeFixed2ByteInt(int value, byte[] buffer, int offset, boolean littleEndian)
static LinkedBuffer
writeFloat(float value, WriteSession session, LinkedBuffer lb)
Writes the stringified float into theLinkedBuffer
.static LinkedBuffer
writeInt(int value, WriteSession session, LinkedBuffer lb)
Writes the stringified int into theLinkedBuffer
.static LinkedBuffer
writeLong(long value, WriteSession session, LinkedBuffer lb)
Writes the stringified long into theLinkedBuffer
.(package private) static LinkedBuffer
writeUTF8(java.lang.CharSequence str, int i, int len, byte[] buffer, int offset, int limit, WriteSession session, LinkedBuffer lb)
Slow path.(package private) static LinkedBuffer
writeUTF8(java.lang.CharSequence str, int i, int len, WriteSession session, LinkedBuffer lb)
Fast path.static LinkedBuffer
writeUTF8(java.lang.CharSequence str, WriteSession session, LinkedBuffer lb)
Writes the utf8-encoded bytes from the string into theLinkedBuffer
.static LinkedBuffer
writeUTF8FixedDelimited(java.lang.CharSequence str, boolean littleEndian, WriteSession session, LinkedBuffer lb)
The length of the utf8 bytes is written first before the string - which is fixed 2-bytes.static LinkedBuffer
writeUTF8FixedDelimited(java.lang.CharSequence str, WriteSession session, LinkedBuffer lb)
The length of the utf8 bytes is written first (big endian) before the string - which is fixed 2-bytes.private static LinkedBuffer
writeUTF8OneByteDelimited(java.lang.CharSequence str, int index, int len, WriteSession session, LinkedBuffer lb)
private static LinkedBuffer
writeUTF8VarDelimited(java.lang.CharSequence str, int index, int len, int lowerLimit, int expectedSize, WriteSession session, LinkedBuffer lb)
static LinkedBuffer
writeUTF8VarDelimited(java.lang.CharSequence str, WriteSession session, LinkedBuffer lb)
The length of the utf8 bytes is written first before the string - which is a variable int (1 to 5 bytes).
-
-
-
Field Detail
-
sizeTable
static final int[] sizeTable
FromInteger.toString(int)
-
DigitTens
static final char[] DigitTens
-
DigitOnes
static final char[] DigitOnes
-
digits
static final char[] digits
-
INT_MIN_VALUE
static final byte[] INT_MIN_VALUE
-
LONG_MIN_VALUE
static final byte[] LONG_MIN_VALUE
-
TWO_BYTE_LOWER_LIMIT
static final int TWO_BYTE_LOWER_LIMIT
- See Also:
- Constant Field Values
-
ONE_BYTE_EXCLUSIVE
static final int ONE_BYTE_EXCLUSIVE
- See Also:
- Constant Field Values
-
THREE_BYTE_LOWER_LIMIT
static final int THREE_BYTE_LOWER_LIMIT
- See Also:
- Constant Field Values
-
TWO_BYTE_EXCLUSIVE
static final int TWO_BYTE_EXCLUSIVE
- See Also:
- Constant Field Values
-
FOUR_BYTE_LOWER_LIMIT
static final int FOUR_BYTE_LOWER_LIMIT
- See Also:
- Constant Field Values
-
THREE_BYTE_EXCLUSIVE
static final int THREE_BYTE_EXCLUSIVE
- See Also:
- Constant Field Values
-
FIVE_BYTE_LOWER_LIMIT
static final int FIVE_BYTE_LOWER_LIMIT
- See Also:
- Constant Field Values
-
FOUR_BYTE_EXCLUSIVE
static final int FOUR_BYTE_EXCLUSIVE
- See Also:
- Constant Field Values
-
-
Method Detail
-
putBytesFromInt
static void putBytesFromInt(int i, int offset, int size, byte[] buf)
-
putBytesFromLong
static void putBytesFromLong(long i, int offset, int size, byte[] buf)
-
stringSize
static int stringSize(int x)
-
stringSize
static int stringSize(long x)
-
writeInt
public static LinkedBuffer writeInt(int value, WriteSession session, LinkedBuffer lb)
Writes the stringified int into theLinkedBuffer
.
-
writeLong
public static LinkedBuffer writeLong(long value, WriteSession session, LinkedBuffer lb)
Writes the stringified long into theLinkedBuffer
.
-
writeFloat
public static LinkedBuffer writeFloat(float value, WriteSession session, LinkedBuffer lb)
Writes the stringified float into theLinkedBuffer
. TODO - skip string conversion and write directly to buffer
-
writeDouble
public static LinkedBuffer writeDouble(double value, WriteSession session, LinkedBuffer lb)
Writes the stringified double into theLinkedBuffer
. TODO - skip string conversion and write directly to buffer
-
computeUTF8Size
public static int computeUTF8Size(java.lang.CharSequence str, int index, int len)
Computes the size of the utf8 string beginning at the specifiedindex
with the specifiedlength
.
-
writeUTF8
static LinkedBuffer writeUTF8(java.lang.CharSequence str, int i, int len, byte[] buffer, int offset, int limit, WriteSession session, LinkedBuffer lb)
Slow path. It checks the limit before every write. Shared with StreamedStringSerializer.
-
writeUTF8
static LinkedBuffer writeUTF8(java.lang.CharSequence str, int i, int len, WriteSession session, LinkedBuffer lb)
Fast path. TheLinkedBuffer
's capacity is >= string length.
-
writeUTF8
public static LinkedBuffer writeUTF8(java.lang.CharSequence str, WriteSession session, LinkedBuffer lb)
Writes the utf8-encoded bytes from the string into theLinkedBuffer
.
-
writeAscii
public static LinkedBuffer writeAscii(java.lang.CharSequence str, WriteSession session, LinkedBuffer lb)
Writes the ascii bytes from the string into theLinkedBuffer
. It is the responsibility of the caller to know in advance that the string is 100% ascii. E.g if you convert a double/float to a string, you are sure it only contains ascii chars.
-
writeFixed2ByteInt
static void writeFixed2ByteInt(int value, byte[] buffer, int offset, boolean littleEndian)
-
writeUTF8FixedDelimited
public static LinkedBuffer writeUTF8FixedDelimited(java.lang.CharSequence str, WriteSession session, LinkedBuffer lb)
The length of the utf8 bytes is written first (big endian) before the string - which is fixed 2-bytes. Same behavior asDataOutputStream.writeUTF(String)
.
-
writeUTF8FixedDelimited
public static LinkedBuffer writeUTF8FixedDelimited(java.lang.CharSequence str, boolean littleEndian, WriteSession session, LinkedBuffer lb)
The length of the utf8 bytes is written first before the string - which is fixed 2-bytes.
-
writeUTF8OneByteDelimited
private static LinkedBuffer writeUTF8OneByteDelimited(java.lang.CharSequence str, int index, int len, WriteSession session, LinkedBuffer lb)
-
writeUTF8VarDelimited
private static LinkedBuffer writeUTF8VarDelimited(java.lang.CharSequence str, int index, int len, int lowerLimit, int expectedSize, WriteSession session, LinkedBuffer lb)
-
writeUTF8VarDelimited
public static LinkedBuffer writeUTF8VarDelimited(java.lang.CharSequence str, WriteSession session, LinkedBuffer lb)
The length of the utf8 bytes is written first before the string - which is a variable int (1 to 5 bytes).
-
highSurrogate
public static char highSurrogate(int codePoint)
-
lowSurrogate
public static char lowSurrogate(int codePoint)
-
-