reworked reading of cstrings (using BV{ } now) - not sure about using read-until

db4
Sascha Matzke 2009-01-31 11:51:30 +01:00
parent af9f0f32df
commit 9838b6fee1
2 changed files with 20 additions and 17 deletions

View File

@ -1,7 +1,7 @@
USING: mirrors io io.encodings.utf8 io.encodings.binary math kernel sequences USING: mirrors io io.encodings.utf8 io.encodings.binary math kernel sequences
splitting accessors io.streams.byte-array namespaces prettyprint splitting accessors io.streams.byte-array namespaces prettyprint
bson.constants assocs alien.c-types alien.strings fry words bson.constants assocs alien.c-types alien.strings fry words
serialize byte-arrays ; serialize byte-arrays byte-vectors ;
IN: bson.reader IN: bson.reader
@ -60,15 +60,16 @@ GENERIC: element-binary-read ( length type -- object )
: read-byte ( -- byte ) : read-byte ( -- byte )
read-byte-raw *char ; inline read-byte-raw *char ; inline
: (read-cstring) ( acc -- acc ) : (read-cstring) ( acc -- )
read-byte-raw dup [ read-byte-raw first ] dip ! b acc
B{ 0 } = 2dup push ! b acc
[ append ] [ 0 = ] dip ! bool acc
[ append (read-cstring) ] if ; inline recursive '[ _ (read-cstring) ] unless ; inline recursive
: read-cstring ( -- string ) : read-cstring ( -- string )
B{ } clone BV{ } clone
(read-cstring) utf8 alien>string ; inline [ (read-cstring) ] keep
>byte-array utf8 alien>string ; inline
: read-sized-string ( length -- string ) : read-sized-string ( length -- string )
[ read ] [ count-bytes ] bi [ read ] [ count-bytes ] bi

View File

@ -1,6 +1,7 @@
USING: io io.encodings.utf8 io.encodings.binary alien.c-types alien.strings math USING: io io.encodings.utf8 io.encodings.binary alien.c-types alien.strings math
bson.writer sequences kernel accessors io.streams.byte-array fry generalizations bson.writer sequences kernel accessors io.streams.byte-array fry generalizations
combinators bson.reader sequences tools.walker assocs strings linked-assocs namespaces ; combinators bson.reader sequences tools.walker assocs strings linked-assocs namespaces
byte-vectors byte-arrays ;
IN: mongodb.msg IN: mongodb.msg
@ -146,17 +147,18 @@ SYMBOL: msg-bytes-read
: read-int32 ( -- int32 ) 4 [ read *int ] [ change-bytes-read ] bi ; inline : read-int32 ( -- int32 ) 4 [ read *int ] [ change-bytes-read ] bi ; inline
: read-longlong ( -- longlong ) 8 [ read *longlong ] [ change-bytes-read ] bi ; inline : read-longlong ( -- longlong ) 8 [ read *longlong ] [ change-bytes-read ] bi ; inline
: read-byte-raw ( -- byte-raw ) 1 [ read ] [ change-bytes-read ] bi ; inline : read-byte-raw ( -- byte-raw ) 1 [ read ] [ change-bytes-read ] bi ; inline
: read-byte ( -- byte ) read-byte-raw *char ; inline : read-byte ( -- byte ) read-byte-raw first ; inline
: (read-cstring) ( acc -- acc ) : (read-cstring) ( acc -- )
read-byte-raw dup [ read-byte ] dip ! b acc
B{ 0 } = 2dup push ! b acc
[ append ] [ 0 = ] dip ! bool acc
[ append (read-cstring) ] if ; recursive inline '[ _ (read-cstring) ] unless ; inline recursive
: read-cstring ( -- string ) : read-cstring ( -- string )
B{ } clone BV{ } clone
(read-cstring) utf8 alien>string ; inline [ (read-cstring) ] keep
>byte-array utf8 alien>string ; inline
GENERIC: (read-message) ( message opcode -- message ) GENERIC: (read-message) ( message opcode -- message )