Package io.protostuff

Class StringSerializer


  • public final class StringSerializer
    extends java.lang.Object
    UTF-8 String serialization
    • Field Detail

      • sizeTable

        static final int[] sizeTable
        From Integer.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
    • Constructor Detail

      • StringSerializer

        private StringSerializer()
    • 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)
      • computeUTF8Size

        public static int computeUTF8Size​(java.lang.CharSequence str,
                                          int index,
                                          int len)
        Computes the size of the utf8 string beginning at the specified index with the specified length.
      • 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.
      • writeAscii

        public static LinkedBuffer writeAscii​(java.lang.CharSequence str,
                                              WriteSession session,
                                              LinkedBuffer lb)
        Writes the ascii bytes from the string into the LinkedBuffer. 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 as DataOutputStream.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.
      • 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)