change _length key name

main
Matthew Butterick 6 years ago
parent b3b6bc386d
commit 686d4e76aa

@ -30,7 +30,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
(mhasheq 'parent parent
x:start-offset-key (pos port)
x:current-offset-key 0
'_length @len)
x:length-key @len)
parent))
(define len (resolve-length @len port parent))
(cond
@ -39,8 +39,8 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
;; resolved-len is byte length
[len (+ (pos port) len)]
;; no resolved-len, but parent has length
[(and parent (not (zero? (dict-ref parent '_length))))
(+ (dict-ref parent x:start-offset-key) (dict-ref parent '_length))]
[(and parent (not (zero? (dict-ref parent x:length-key))))
(+ (dict-ref parent x:start-offset-key) (dict-ref parent x:length-key))]
;; no resolved-len or parent, so consume whole stream
[else +inf.0]))
(for/list ([i (in-naturals)]

@ -9,8 +9,9 @@
(define x:version-key 'x:version)
(define x:start-offset-key 'x:start-offset)
(define x:current-offset-key 'x:current-offset)
(define x:length-key 'x:length)
(define private-keys (list 'parent x:start-offset-key x:current-offset-key '_length))
(define private-keys (list 'parent x:start-offset-key x:current-offset-key x:length-key))
(define (dict-ref* d . keys)
(for/fold ([d d])

@ -20,7 +20,7 @@ https://github.com/mbutterick/restructure/blob/master/src/LazyArray.coffee
(mhasheq 'parent parent
x:start-offset-key starting-pos
x:current-offset-key 0
'_length @len)
x:length-key @len)
parent))
(define stream-starting-pos (pos port))
(begin0

@ -19,7 +19,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
'parent parent
x:start-offset-key (pos port)
x:current-offset-key 0
'_length len)
x:length-key len)
mheq)
(define (xstruct-parse-fields port sdr fields-arg)

@ -62,12 +62,12 @@ https://github.com/mbutterick/restructure/blob/master/test/Array.coffee
(test-case
"array: decode to the end of parent if no length given"
(parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))])
(check-equal? (decode (x:array #:type uint8) (current-input-port) #:parent (mhash '_length 4 x:start-offset-key 0)) '(1 2 3 4))))
(check-equal? (decode (x:array #:type uint8) (current-input-port) #:parent (mhash x:length-key 4 x:start-offset-key 0)) '(1 2 3 4))))
(test-case
"array: decode to the end of the stream if parent exists, but its length is 0"
(parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))])
(check-equal? (decode (x:array #:type uint8) (current-input-port) #:parent (mhash '_length 0 x:start-offset-key 0)) '(1 2 3 4 5))))
(check-equal? (decode (x:array #:type uint8) (current-input-port) #:parent (mhash x:length-key 0 x:start-offset-key 0)) '(1 2 3 4 5))))
(test-case
"array: decode to the end of the stream if no parent and length is given"

Loading…
Cancel
Save