1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel accessors alien alien.c-types alien.accessors math io ;
6 TUPLE: memory-stream alien index ;
8 : <memory-stream> ( alien -- stream )
11 M: memory-stream stream-element-type drop +byte+ ;
13 M: memory-stream stream-read1
14 [ [ alien>> ] [ index>> ] bi alien-unsigned-1 ]
15 [ [ 1+ ] change-index drop ] bi ;
17 M: memory-stream stream-read
19 [ index>> ] [ alien>> ] bi <displaced-alien>
20 swap memory>byte-array
21 ] [ [ + ] change-index drop ] 2bi ;