 
 : read-message ( -- message )
     mdb-msg new
+    0 >bytes-read
     read-header
     [ ] [ opcode>> ] bi (read-message) ;
 

    read-cstring >>collection
    read-int32 >>skip#
    read-int32 >>return#
    H{ } stream>assoc >>query ;

M: mdb-insert-op (read-message) ( msg-stub opcode -- message )
    drop
    [ mdb-insert-msg new ] dip copy-header
    read-cstring >>collection
    H{ } stream>assoc >>objects ;

M: mdb-reply-op (read-message) ( msg-stub opcode -- message )
    drop

     ] (write-message) ;
 
M: mdb-insert-msg write-message ( message -- )
    dup
    '[ _
       [ 0 write-int32 ] dip
       [ collection>> write-cstring ] keep
       objects>> [ assoc>array write ] each
    ] (write-message) ;

