Skip to content

Instantly share code, notes, and snippets.

@jharjono
Created November 6, 2012 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jharjono/4023254 to your computer and use it in GitHub Desktop.
Save jharjono/4023254 to your computer and use it in GitHub Desktop.
Snippet from Thrift's TSerializer.java
/**
* Serialize the Thrift object into a byte array. The process is simple,
* just clear the byte array output, write the object into it, and grab the
* raw bytes.
*
* @param base The object to serialize
* @return Serialized object in byte[] format
*/
public byte[] serialize(TBase base) throws TException {
baos_.reset();
base.write(protocol_);
return baos_.toByteArray(); // what happens if another thread calls serialize() right before this line is executed?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment