org.bson
Class BSONEncoder

java.lang.Object
  extended by org.bson.BSONEncoder

public class BSONEncoder
extends Object

this is meant to be pooled or cached there is some per instance memory for string conversion, etc...


Field Summary
protected  OutputBuffer _buf
           
 
Constructor Summary
BSONEncoder()
           
 
Method Summary
protected  void _put(byte type, String name)
          Encodes the type and key.
protected  int _put(String str)
          puts as utf-8 string
protected  void _putObjectField(String name, Object val)
           
protected  void _putValueString(String s)
           
 void done()
           
 byte[] encode(BSONObject o)
           
protected  boolean handleSpecialObjects(String name, BSONObject o)
           
protected  void putBinary(String name, Binary val)
           
protected  void putBinary(String name, byte[] data)
           
protected  void putBoolean(String name, Boolean b)
           
protected  void putCode(String name, Code code)
           
protected  void putCodeWScope(String name, CodeWScope code)
           
protected  void putDate(String name, Date d)
           
protected  void putNull(String name)
           
protected  void putNumber(String name, Number n)
           
 int putObject(BSONObject o)
          Encodes a BSONObject.
protected  void putObjectId(String name, ObjectId oid)
           
protected  boolean putSpecial(String name, Object o)
           
protected  void putString(String name, String s)
           
protected  void putSymbol(String name, Symbol s)
           
protected  void putTimestamp(String name, BSONTimestamp ts)
           
protected  void putUndefined(String name)
           
protected  void putUUID(String name, UUID val)
           
 void set(OutputBuffer out)
           
 void writeCString(String s)
           
 void writeInt(int x)
           
 void writeLong(long x)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_buf

protected OutputBuffer _buf
Constructor Detail

BSONEncoder

public BSONEncoder()
Method Detail

encode

public byte[] encode(BSONObject o)

set

public void set(OutputBuffer out)

done

public void done()

handleSpecialObjects

protected boolean handleSpecialObjects(String name,
                                       BSONObject o)
Returns:
true if object was handled

putSpecial

protected boolean putSpecial(String name,
                             Object o)

putObject

public int putObject(BSONObject o)
Encodes a BSONObject. This is for the higher level api calls

Parameters:
o - the object to encode
Returns:
the number of characters in the encoding

_putObjectField

protected void _putObjectField(String name,
                               Object val)

putNull

protected void putNull(String name)

putUndefined

protected void putUndefined(String name)

putTimestamp

protected void putTimestamp(String name,
                            BSONTimestamp ts)

putCodeWScope

protected void putCodeWScope(String name,
                             CodeWScope code)

putCode

protected void putCode(String name,
                       Code code)

putBoolean

protected void putBoolean(String name,
                          Boolean b)

putDate

protected void putDate(String name,
                       Date d)

putNumber

protected void putNumber(String name,
                         Number n)

putBinary

protected void putBinary(String name,
                         byte[] data)

putBinary

protected void putBinary(String name,
                         Binary val)

putUUID

protected void putUUID(String name,
                       UUID val)

putSymbol

protected void putSymbol(String name,
                         Symbol s)

putString

protected void putString(String name,
                         String s)

putObjectId

protected void putObjectId(String name,
                           ObjectId oid)

_put

protected void _put(byte type,
                    String name)
Encodes the type and key.


_putValueString

protected void _putValueString(String s)

_put

protected int _put(String str)
puts as utf-8 string


writeInt

public void writeInt(int x)

writeLong

public void writeLong(long x)

writeCString

public void writeCString(String s)