 PRIVATE>
 
 : ensure-buffer ( -- )
-    (buffer) drop ;
+    (buffer) drop ; inline
 
 : reset-buffer ( -- )
-    (buffer) 0 >>length drop ;
+    (buffer) 0 >>length drop ; inline
 
 : with-buffer ( quot -- byte-vector )
     [ (buffer) ] dip [ output-stream get ] compose

SYMBOL: shared-buffer 

CONSTANT: INT32-SIZE 4

: (buffer) ( -- buffer )
    shared-buffer get

M: quotation bson-type? ( quotation -- type ) drop T_Binary ; 
M: byte-array bson-type? ( byte-array -- type ) drop T_Binary ; 

: write-byte ( byte -- ) CHAR-SIZE >le write ; inline
: write-int32 ( int -- ) INT32-SIZE >le write ; inline
: write-double ( real -- ) double>bits INT64-SIZE >le write ; inline
: write-cstring ( string -- ) utf8 encode B{ 0 } append write ; inline
: write-longlong ( object -- ) INT64-SIZE >le write ; inline

: write-eoo ( -- ) T_EOO write-byte ; inline
: write-type ( obj -- obj ) [ bson-type? write-byte ] keep ; inline
