com.dyuproject.protostuff
Class StringSerializer

java.lang.Object
  extended by com.dyuproject.protostuff.StringSerializer

public final class StringSerializer
extends java.lang.Object

UTF-8 String serialization

Author:
David Yu
Date created:
Feb 4, 2010

Nested Class Summary
static class StringSerializer.STRING
           
 
Method Summary
static int computeUTF8Size(java.lang.String str, int index, int len)
          Computes the size of the utf8 string beginning at the specified index with the specified length.
static LinkedBuffer writeAscii(java.lang.String str, WriteSession session, LinkedBuffer lb)
          Writes the ascii bytes from the string into the LinkedBuffer.
static LinkedBuffer writeDouble(double value, WriteSession session, LinkedBuffer lb)
          Writes the stringified double into the LinkedBuffer.
static LinkedBuffer writeFloat(float value, WriteSession session, LinkedBuffer lb)
          Writes the stringified float into the LinkedBuffer.
static LinkedBuffer writeInt(int value, WriteSession session, LinkedBuffer lb)
          Writes the stringified int into the LinkedBuffer.
static LinkedBuffer writeLong(long value, WriteSession session, LinkedBuffer lb)
          Writes the stringified long into the LinkedBuffer.
static LinkedBuffer writeUTF8(java.lang.String str, WriteSession session, LinkedBuffer lb)
          Writes the utf8-encoded bytes from the string into the LinkedBuffer.
static LinkedBuffer writeUTF8FixedDelimited(java.lang.String 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.String str, WriteSession session, LinkedBuffer lb)
          The length of the utf8 bytes is written first (big endian) before the string - which is fixed 2-bytes.
static LinkedBuffer writeUTF8VarDelimited(java.lang.String 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).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

writeInt

public static LinkedBuffer writeInt(int value,
                                    WriteSession session,
                                    LinkedBuffer lb)
Writes the stringified int into the LinkedBuffer.


writeLong

public static LinkedBuffer writeLong(long value,
                                     WriteSession session,
                                     LinkedBuffer lb)
Writes the stringified long into the LinkedBuffer.


writeFloat

public static LinkedBuffer writeFloat(float value,
                                      WriteSession session,
                                      LinkedBuffer lb)
Writes the stringified float into the LinkedBuffer. 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 the LinkedBuffer. TODO - skip string conversion and write directly to buffer


computeUTF8Size

public static int computeUTF8Size(java.lang.String str,
                                  int index,
                                  int len)
Computes the size of the utf8 string beginning at the specified index with the specified length.


writeUTF8

public static LinkedBuffer writeUTF8(java.lang.String str,
                                     WriteSession session,
                                     LinkedBuffer lb)
Writes the utf8-encoded bytes from the string into the LinkedBuffer.


writeAscii

public static LinkedBuffer writeAscii(java.lang.String 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.


writeUTF8FixedDelimited

public static LinkedBuffer writeUTF8FixedDelimited(java.lang.String 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.String 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

public static LinkedBuffer writeUTF8VarDelimited(java.lang.String 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).



Copyright © 2009-2013. All Rights Reserved.