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

@ -9,8 +9,9 @@
(define x:version-key 'x:version) (define x:version-key 'x:version)
(define x:start-offset-key 'x:start-offset) (define x:start-offset-key 'x:start-offset)
(define x:current-offset-key 'x:current-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) (define (dict-ref* d . keys)
(for/fold ([d d]) (for/fold ([d d])

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

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

@ -62,12 +62,12 @@ https://github.com/mbutterick/restructure/blob/master/test/Array.coffee
(test-case (test-case
"array: decode to the end of parent if no length given" "array: decode to the end of parent if no length given"
(parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))]) (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 (test-case
"array: decode to the end of the stream if parent exists, but its length is 0" "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))]) (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 (test-case
"array: decode to the end of the stream if no parent and length is given" "array: decode to the end of the stream if no parent and length is given"

Loading…
Cancel
Save