|
|
|
@ -14,7 +14,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
|
|
|
|
|
|#
|
|
|
|
|
|
|
|
|
|
(define xarray-base%
|
|
|
|
|
(class* xenobase% ()
|
|
|
|
|
(class xenobase%
|
|
|
|
|
(super-new)
|
|
|
|
|
(init-field type len)
|
|
|
|
|
(unless (xenomorphic? type)
|
|
|
|
@ -23,7 +23,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
|
|
|
|
|
(raise-argument-error '+xarray "length-resolvable?" len))))
|
|
|
|
|
|
|
|
|
|
(define xarray%
|
|
|
|
|
(class* xarray-base% ()
|
|
|
|
|
(class xarray-base%
|
|
|
|
|
(super-new)
|
|
|
|
|
(init-field length-type)
|
|
|
|
|
(unless (memq length-type '(bytes count))
|
|
|
|
@ -38,22 +38,22 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
|
|
|
|
|
'_currentOffset 0
|
|
|
|
|
'_length len)
|
|
|
|
|
parent))
|
|
|
|
|
(define decoded-len (resolve-length len #:parent parent))
|
|
|
|
|
(define resolved-len (resolve-length len #:parent parent))
|
|
|
|
|
(cond
|
|
|
|
|
[(or (not decoded-len) (eq? length-type 'bytes))
|
|
|
|
|
[(or (not resolved-len) (eq? length-type 'bytes))
|
|
|
|
|
(define end-pos (cond
|
|
|
|
|
;; decoded-len is byte length
|
|
|
|
|
[decoded-len (+ (pos port) decoded-len)]
|
|
|
|
|
;; no decoded-len, but parent has length
|
|
|
|
|
;; resolved-len is byte length
|
|
|
|
|
[resolved-len (+ (pos port) resolved-len)]
|
|
|
|
|
;; no resolved-len, but parent has length
|
|
|
|
|
[(and parent (not (zero? (dict-ref parent '_length))))
|
|
|
|
|
(+ (dict-ref parent '_startOffset) (dict-ref parent '_length))]
|
|
|
|
|
;; no decoded-len or parent, so consume whole stream
|
|
|
|
|
;; no resolved-len or parent, so consume whole stream
|
|
|
|
|
[else +inf.0]))
|
|
|
|
|
(for/list ([i (in-naturals)]
|
|
|
|
|
#:break (or (eof-object? (peek-byte)) (= (pos port) end-pos)))
|
|
|
|
|
(send type xxdecode port new-parent))]
|
|
|
|
|
;; we have decoded-len, which is treated as count of items
|
|
|
|
|
[else (for/list ([i (in-range decoded-len)])
|
|
|
|
|
;; we have resolved-len, which is treated as count of items
|
|
|
|
|
[else (for/list ([i (in-range resolved-len)])
|
|
|
|
|
(send type xxdecode port new-parent))]))
|
|
|
|
|
|
|
|
|
|
(define/augment (xxencode array port [parent #f])
|
|
|
|
|