From 686d4e76aaa7256caf7a2a81baf8602bf3e4bc41 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 17 Dec 2018 17:10:11 -0800 Subject: [PATCH] change _length key name --- xenomorph/xenomorph/array.rkt | 6 +++--- xenomorph/xenomorph/helper.rkt | 3 ++- xenomorph/xenomorph/lazy-array.rkt | 2 +- xenomorph/xenomorph/struct.rkt | 2 +- xenomorph/xenomorph/test/array-test.rkt | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/xenomorph/xenomorph/array.rkt b/xenomorph/xenomorph/array.rkt index a3bef851..b3df90f5 100644 --- a/xenomorph/xenomorph/array.rkt +++ b/xenomorph/xenomorph/array.rkt @@ -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)] diff --git a/xenomorph/xenomorph/helper.rkt b/xenomorph/xenomorph/helper.rkt index 8dd9082f..9eaab147 100644 --- a/xenomorph/xenomorph/helper.rkt +++ b/xenomorph/xenomorph/helper.rkt @@ -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]) diff --git a/xenomorph/xenomorph/lazy-array.rkt b/xenomorph/xenomorph/lazy-array.rkt index 47019eb9..d3cd6efe 100644 --- a/xenomorph/xenomorph/lazy-array.rkt +++ b/xenomorph/xenomorph/lazy-array.rkt @@ -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 diff --git a/xenomorph/xenomorph/struct.rkt b/xenomorph/xenomorph/struct.rkt index 81951e58..77a3414f 100644 --- a/xenomorph/xenomorph/struct.rkt +++ b/xenomorph/xenomorph/struct.rkt @@ -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) diff --git a/xenomorph/xenomorph/test/array-test.rkt b/xenomorph/xenomorph/test/array-test.rkt index 3f365199..d8316fcd 100644 --- a/xenomorph/xenomorph/test/array-test.rkt +++ b/xenomorph/xenomorph/test/array-test.rkt @@ -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"