resume in writeString

main
Matthew Butterick 8 years ago
parent d4c0b0b010
commit 18305b8d2f

@ -146,6 +146,13 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee
; string = new StringT 7
; string.encode(stream, 'testing')
; stream.end()
(let ([string (+StringT 7)]
[stream (+EncodeStream)])
(send string encode stream "testing")
(check-equal? (send stream dump) "testing"))
;
; it 'should encode length as number before string', (done) ->
; stream = new EncodeStream

@ -30,13 +30,18 @@ https://github.com/mbutterick/restructure/blob/master/src/String.coffee
string)
#;(define/augment (encode stream val [parent #f])
(define bytes (($codec-encoder codec) (format "~a" val)))
(define/augment (encode stream val [parent #f])
(define encoding__
(cond
[(procedure? encoding_) (or (encoding_ (and parent (· parent val)) 'ascii))]
[else encoding_]))
(when (NumberT? length_)
(send length_ encode stream (byteLength val encoding__)))
(send stream writeString val encoding__)
(when (not length_)
(send stream writeUInt8 #x00)))
(when (Number? length_) ;; length-prefixed string
(send length_ encode stream (bytes-length bytes)))
(send stream write bytes))
(define/override (size [val #f] [parent #f])
;; Use the defined value if no value was given

Loading…
Cancel
Save