buffer tests pass

main
Matthew Butterick 8 years ago
parent 79fdb76499
commit cca4e2ea1d

@ -1,5 +1,5 @@
#lang restructure/racket
(require "buffer.rkt" "stream.rkt" rackunit)
(require "buffer.rkt" "stream.rkt" "number.rkt" rackunit)
#|
approximates
@ -65,12 +65,13 @@ https://github.com/mbutterick/restructure/blob/master/test/Buffer.coffee
; stream.end()
;
(let ([buf (+BufferT 2)]
[stream (+EncodeStream)])
(let ([stream (+EncodeStream)]
[buf (+BufferT 2)])
(send buf encode stream (+Buffer '(#xab #xff)))
(send buf encode stream (+Buffer '(#x1f #xb6)))
(check-equal? (send stream dump) (+Buffer '(#xab #xff #x1f #xb6))))
; it 'should encode length before buffer', (done) ->
; stream = new EncodeStream
; stream.pipe concat (buf) ->
@ -79,4 +80,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Buffer.coffee
;
; buf = new BufferT(uint8)
; buf.encode stream, new Buffer [0xab, 0xff]
; stream.end()
; stream.end()
(let ([stream (+EncodeStream)]
[buf (+BufferT uint8)])
(send buf encode stream (+Buffer '(#xab #xff)))
(check-equal? (send stream dump) (+Buffer '(2 #xab #xff))))

@ -33,14 +33,12 @@ A Restructure RBuffer object is separate.
(bytes-length val)
(utils-resolveLength length_ val parent)))
(define/override (encode stream buf-in [parent #f])
(define buf (if (bytes? buf-in) (bytes->list buf-in) buf-in))
(unless (and (list? buf) (andmap byte? buf))
(raise-argument-error 'Buffer:encode "list of bytes" buf))
(report* buf length_)
(define/override (encode stream buf [parent #f])
(unless (bytes? buf)
(raise-argument-error 'Buffer:encode "bytes" buf))
(when (NumberT? length_)
(send length_ encode stream (*length buf))
(send stream writeBuffer buf))))
(send length_ encode stream (*length buf)))
(send stream writeBuffer buf)))
(define-subclass RBuffer (BufferT))

@ -66,8 +66,8 @@ https://github.com/mbutterick/restructure/blob/master/src/Number.coffee
(define bstr (apply bytes ((if (eq? endian 'be) identity reverse) bs)))
(send stream write bstr)))
(define-subclass Integer (Number))
(define-subclass Integer (NumberT))
(define-values (NumberT NumberT? +NumberT) (values Integer Integer? +Integer))
(define-values (Number Number? +Number) (values Integer Integer? +Integer))
(define-subclass Streamcoder (Float _size [endian system-endian])
(define byte-size (/ _size 8))

Loading…
Cancel
Save