xx → x:

main
Matthew Butterick 6 years ago
parent a5476dfd49
commit dbe0a8099f

@ -25,7 +25,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
(unless (memq @length-type '(bytes count))
(raise-argument-error '+xarray "'bytes or 'count" @length-type))
(define/augride (xxdecode port parent)
(define/augride (x:decode port parent)
(define new-parent (if (xint? @len)
(mhasheq 'parent parent
'_startOffset (pos port)
@ -45,12 +45,12 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
[else +inf.0]))
(for/list ([i (in-naturals)]
#:break (or (eof-object? (peek-byte port)) (= (pos port) end-pos)))
(send @type xxdecode port new-parent))]
(send @type x:decode port new-parent))]
;; we have resolved-len, which is treated as count of items
[else (for/list ([i (in-range len)])
(send @type xxdecode port new-parent))]))
(send @type x:decode port new-parent))]))
(define/augride (xxencode array port [parent #f])
(define/augride (x:encode array port [parent #f])
(unless (sequence? array)
(raise-argument-error 'xarray-encode "sequence" array))
(define (encode-items parent)
@ -60,32 +60,32 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
#;[item-count (length items)]
#;[max-items (if (number? (xarray-len xa)) (xarray-len xa) item-count)])
(for ([item array])
(send @type xxencode item port parent))))
(send @type x:encode item port parent))))
(cond
[(xint? @len)
(define new-parent (mhash 'pointers null
'startOffset (pos port)
'parent parent))
(dict-set! new-parent 'pointerOffset (+ (pos port) (xxsize array new-parent)))
(send @len xxencode (length array) port) ; encode length at front
(dict-set! new-parent 'pointerOffset (+ (pos port) (x:size array new-parent)))
(send @len x:encode (length array) port) ; encode length at front
(encode-items new-parent)
(for ([ptr (in-list (dict-ref new-parent 'pointers))]) ; encode pointer data at end
(send (dict-ref ptr 'type) xxencode (dict-ref ptr 'val) port))]
(send (dict-ref ptr 'type) x:encode (dict-ref ptr 'val) port))]
[else (encode-items parent)]))
(define/augride (xxsize [val #f] [parent #f])
(define/augride (x:size [val #f] [parent #f])
(when val (unless (sequence? val)
(raise-argument-error 'xarray-size "sequence" val)))
(cond
[val (define-values (new-parent len-size)
(if (xint? @len)
(values (mhasheq 'parent parent) (send @len xxsize))
(values (mhasheq 'parent parent) (send @len x:size))
(values parent 0)))
(define items-size (for/sum ([item val])
(send @type xxsize item new-parent)))
(send @type x:size item new-parent)))
(+ items-size len-size)]
[else (define count (resolve-length @len #f #:parent parent))
(define size (send @type xxsize #f parent))
(define size (send @type x:size #f parent))
(* size count)]))))
(define (+xarray [type-arg #f] [len-arg #f] [length-type-arg 'count]

@ -14,22 +14,22 @@ https://github.com/mbutterick/restructure/blob/master/src/Bitfield.coffee
(unless (andmap (λ (f) (or (symbol? f) (not f))) @flags)
(raise-argument-error '+xbitfield "list of symbols" @flags))
(define/augment (xxdecode port parent)
(define val (send @type xxdecode port))
(define/augment (x:decode port parent)
(define val (send @type x:decode port))
(define flag-hash (mhasheq))
(for ([(flag idx) (in-indexed @flags)]
#:when flag)
(hash-set! flag-hash flag (bitwise-bit-set? val idx)))
flag-hash)
(define/augment (xxencode flag-hash port [parent #f])
(define/augment (x:encode flag-hash port [parent #f])
(define bit-int (for/sum ([(flag idx) (in-indexed @flags)]
#:when (and flag (dict-ref flag-hash flag #f)))
(arithmetic-shift 1 idx)))
(send @type xxencode bit-int port))
(send @type x:encode bit-int port))
(define/augment (xxsize [val #f] [parent #f])
(send @type xxsize))))
(define/augment (x:size [val #f] [parent #f])
(send @type x:size))))
(define (+xbitfield [type-arg #f] [flag-arg #f]
#:type [type-kwarg #f]

@ -14,18 +14,18 @@ https://github.com/mbutterick/restructure/blob/master/src/Buffer.coffee
(unless (length-resolvable? @len)
(raise-argument-error '+xbuffer "resolvable length" @len))
(define/augment (xxdecode port parent)
(define/augment (x:decode port parent)
(define len (resolve-length @len port #:parent parent))
(read-bytes len))
(define/augment (xxencode buf port [parent #f])
(define/augment (x:encode buf port [parent #f])
(unless (bytes? buf)
(raise-argument-error 'xbuffer-encode "bytes" buf))
(when (xint? @len)
(send @len xxencode (bytes-length buf) port))
(send @len x:encode (bytes-length buf) port))
(write-bytes buf port))
(define/augment (xxsize [val #f] [parent #f])
(define/augment (x:size [val #f] [parent #f])
(when val (unless (bytes? val)
(raise-argument-error 'xbuffer-size "bytes" val)))
(if (bytes? val)

@ -17,18 +17,18 @@ https://github.com/mbutterick/restructure/blob/master/src/Enum.coffee
(unless (list? @values)
(raise-argument-error '+xenum "list of values" @values))
(define/augment (xxdecode port parent)
(define index (send @type xxdecode port parent))
(define/augment (x:decode port parent)
(define index (send @type x:decode port parent))
(or (list-ref @values index) index))
(define/augment (xxencode val port [parent #f])
(define/augment (x:encode val port [parent #f])
(define index (index-of @values val))
(unless index
(raise-argument-error 'xenum-encode "valid option" val))
(send @type xxencode index port parent))
(send @type x:encode index port parent))
(define/augment (xxsize [val #f] [parent #f])
(send @type xxsize val parent))))
(define/augment (x:size [val #f] [parent #f])
(send @type x:size val parent))))
(define (+xenum [type-arg #f] [values-arg #f]
#:type [type-kwarg #f]

@ -32,11 +32,11 @@
(define (encode xo val [port-arg (current-output-port)]
#:parent [parent #f])
(define port (if (output-port? port-arg) port-arg (open-output-bytes)))
(send xo xxencode val port parent)
(send xo x:encode val port parent)
(unless port-arg (get-output-bytes port)))
(define (size xo [val #f] #:parent [parent #f])
(send xo xxsize val parent)))])))
(send xo x:size val parent)))])))
(define (xenomorphic-type? x) (is-a? x xenobase%))
@ -61,18 +61,18 @@
(class* object% (xenomorphic<%>)
(super-new)
(define/pubment (xxdecode input-port [parent #f])
(post-decode (inner (error 'xxdecode-not-augmented) xxdecode input-port parent)))
(define/pubment (x:decode input-port [parent #f])
(post-decode (inner (error 'x:decode-not-augmented) x:decode input-port parent)))
(define/public (decode input-port [parent #f])
(xxdecode input-port parent))
(x:decode input-port parent))
(define/pubment (xxencode val output-port [parent #f])
(define encode-result (inner (error 'xxencode-not-augmented) xxencode (pre-encode val) output-port parent))
(define/pubment (x:encode val output-port [parent #f])
(define encode-result (inner (error 'x:encode-not-augmented) x:encode (pre-encode val) output-port parent))
(when (bytes? encode-result) (write-bytes encode-result output-port)))
(define/pubment (xxsize [val #f] [parent #f] . args)
(define size (inner 0 xxsize val parent . args))
(define/pubment (x:size [val #f] [parent #f] . args)
(define size (inner 0 x:size val parent . args))
(unless (and (integer? size) (not (negative? size)))
(raise-argument-error 'size "nonnegative integer" size))
size)

@ -13,7 +13,7 @@ https://github.com/mbutterick/restructure/blob/master/src/LazyArray.coffee
(super-new)
(inherit-field [@type type] [@len len])
(define/override (xxdecode port parent)
(define/override (x:decode port parent)
(define starting-pos (pos port)) ; ! placement matters. `resolve-length` will change `pos`
(define len (resolve-length @len port #:parent parent))
(define new-parent (if (xint? @len)
@ -26,17 +26,17 @@ https://github.com/mbutterick/restructure/blob/master/src/LazyArray.coffee
(begin0
(for/stream ([index (in-range len)])
(define orig-pos (pos port))
(pos port (+ stream-starting-pos (* (send @type xxsize #f new-parent) index)))
(pos port (+ stream-starting-pos (* (send @type x:size #f new-parent) index)))
(begin0
(send @type xxdecode port new-parent)
(send @type x:decode port new-parent)
(pos port orig-pos)))
(pos port (+ (pos port) (* len (send @type xxsize #f new-parent))))))
(pos port (+ (pos port) (* len (send @type x:size #f new-parent))))))
(define/override (xxencode val port [parent #f])
(super xxencode (if (stream? val) (stream->list val) val) port parent))
(define/override (x:encode val port [parent #f])
(super x:encode (if (stream? val) (stream->list val) val) port parent))
(define/override (xxsize [val #f] [parent #f])
(super xxsize (if (stream? val) (stream->list val) val) parent))))
(define/override (x:size [val #f] [parent #f])
(super x:size (if (stream? val) (stream->list val) val) parent))))
(define (+xlazy-array [type-arg #f] [len-arg #f]
#:type [type-kwarg #f]

@ -35,7 +35,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Number.coffee
(field [@bits (* @size 8)])
(define/augment (xxsize . _) @size)))
(define/augment (x:size . _) @size)))
(define (xint? x) (is-a? x xint%))
@ -53,14 +53,14 @@ https://github.com/mbutterick/restructure/blob/master/src/Number.coffee
(field [bound-min (- signed-min delta)]
[bound-max (- signed-max delta)])
(define/augment (xxdecode port . _)
(define/augment (x:decode port . _)
(define bs ((if (eq? @endian system-endian) values reverse-bytes) (read-bytes @size port)))
(define uint (for/sum ([b (in-bytes bs)]
[i (in-naturals)])
(arithmetic-shift b (* 8 i))))
(if signed (unsigned->signed uint @bits) uint))
(define/augment (xxencode val . _)
(define/augment (x:encode val . _)
(unless (<= bound-min val bound-max)
(raise-argument-error 'encode
(format "value that fits within ~a ~a-byte int (~a to ~a)" (if signed "signed" "unsigned") @size bound-min bound-max) val))
@ -150,10 +150,10 @@ https://github.com/mbutterick/restructure/blob/master/src/Number.coffee
(super-new)
(inherit-field (@size size) (@endian endian))
(define/augment (xxdecode port . _)
(define/augment (x:decode port . _)
(floating-point-bytes->real (read-bytes @size port) (eq? @endian 'be)))
(define/augment (xxencode val . _)
(define/augment (x:encode val . _)
(real->floating-point-bytes val @size (eq? @endian 'be)))))
(define (+xfloat [size 4] #:endian [endian system-endian]

@ -19,16 +19,16 @@ https://github.com/mbutterick/restructure/blob/master/src/Optional.coffee
(define maybe-proc @condition)
(if (procedure? maybe-proc) (maybe-proc parent) maybe-proc))
(define/augment (xxdecode port parent)
(define/augment (x:decode port parent)
(when (resolve-condition parent)
(send @type xxdecode port parent)))
(send @type x:decode port parent)))
(define/augment (xxencode val port [parent #f])
(define/augment (x:encode val port [parent #f])
(when (resolve-condition parent)
(send @type xxencode val port parent)))
(send @type x:encode val port parent)))
(define/augment (xxsize [val #f] [parent #f])
(if (resolve-condition parent) (send @type xxsize val parent) 0))))
(define/augment (x:size [val #f] [parent #f])
(if (resolve-condition parent) (send @type x:size val parent) 0))))
(define no-val (gensym))

@ -33,14 +33,14 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
[(@null-value null-value)]
[(@pointer-lazy? pointer-lazy?)])
(define/augment (xxdecode port parent)
(define offset (send @offset-type xxdecode port parent))
(define/augment (x:decode port parent)
(define offset (send @offset-type x:decode port parent))
(cond
[(and @allow-null? (= offset @null-value)) #f] ; handle null pointers
[else
(define relative (+ (case @pointer-relative-to
[(local) (dict-ref parent '_startOffset)]
[(immediate) (- (pos port) (send @offset-type xxsize))]
[(immediate) (- (pos port) (send @offset-type x:size))]
[(parent) (dict-ref (dict-ref parent 'parent) '_startOffset)]
[(global) (or (dict-ref (find-top-parent parent) '_startOffset) 0)]
[else (error 'unknown-pointer-style)])))
@ -50,12 +50,12 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
(define orig-pos (pos port))
(pos port ptr)
(begin0
(send @type xxdecode port parent)
(send @type x:decode port parent)
(pos port orig-pos)))
(if @pointer-lazy? (delay (decode-value)) (decode-value))]
[else ptr])]))
(define/augment (xxencode val-in port [parent #f])
(define/augment (x:encode val-in port [parent #f])
(unless parent ; todo: furnish default pointer context? adapt from Struct?
(raise-argument-error 'xpointer-encode "valid pointer context" parent))
(cond
@ -67,17 +67,17 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
[else (error 'unknown-pointer-style)]))
(define relative (+ (case @pointer-relative-to
[(local parent) (dict-ref new-parent 'startOffset)]
[(immediate) (+ (pos port) (send @offset-type xxsize val-in parent))]
[(immediate) (+ (pos port) (send @offset-type x:size val-in parent))]
[(global) 0])))
(send @offset-type xxencode (- (dict-ref new-parent 'pointerOffset) relative) port)
(send @offset-type x:encode (- (dict-ref new-parent 'pointerOffset) relative) port)
(define-values (type val) (resolve-pointer @type val-in))
(dict-update! new-parent 'pointers
(λ (ptrs) (append ptrs (list (mhasheq 'type type 'val val 'parent parent)))))
(dict-set! new-parent 'pointerOffset
(+ (dict-ref new-parent 'pointerOffset) (send type xxsize val parent)))]
[else (send @offset-type xxencode @null-value port)]))
(+ (dict-ref new-parent 'pointerOffset) (send type x:size val parent)))]
[else (send @offset-type x:encode @null-value port)]))
(define/augment (xxsize [val-in #f] [parent #f])
(define/augment (x:size [val-in #f] [parent #f])
(define new-parent (case @pointer-relative-to
[(local immediate) parent]
[(parent) (dict-ref parent 'parent)]
@ -87,8 +87,8 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
(when (and val new-parent)
(dict-set! new-parent 'pointerSize
(and (dict-ref new-parent 'pointerSize #f)
(+ (dict-ref new-parent 'pointerSize) (send type xxsize val new-parent)))))
(send @offset-type xxsize))))
(+ (dict-ref new-parent 'pointerSize) (send type x:size val new-parent)))))
(send @offset-type x:size))))
(define (+xpointer [offset-arg #f] [type-arg #f]
#:offset-type [offset-kwarg #f]

@ -15,15 +15,15 @@ https://github.com/mbutterick/restructure/blob/master/src/Reserved.coffee
(unless (xenomorphic-type? @type)
(raise-argument-error '+xoptional"xenomorphic type" @type))
(define/augment (xxdecode port parent)
(pos port (+ (pos port) (xxsize #f parent)))
(define/augment (x:decode port parent)
(pos port (+ (pos port) (x:size #f parent)))
(void))
(define/augment (xxencode val port [parent #f])
(make-bytes (xxsize val parent) 0))
(define/augment (x:encode val port [parent #f])
(make-bytes (x:size val parent) 0))
(define/augment (xxsize [val #f] [parent #f])
(* (send @type xxsize) (resolve-length @count #f #:parent parent)))))
(define/augment (x:size [val #f] [parent #f])
(* (send @type x:size) (resolve-length @count #f #:parent parent)))))
(define (+xreserved [type-arg #f] [count-arg #f]
#:type [type-kwarg #f]

@ -38,7 +38,7 @@ https://github.com/mbutterick/restructure/blob/master/src/String.coffee
(unless (or (procedure? @encoding) (memq @encoding supported-encodings))
(raise-argument-error 'xstring (format "procedure or member of ~v" supported-encodings) @encoding))
(define/augment (xxdecode port parent)
(define/augment (x:decode port parent)
(define len (or (resolve-length @len port #:parent parent) (count-nonzero-chars port)))
(define encoding (if (procedure? @encoding)
(or (@encoding parent) 'ascii)
@ -48,7 +48,7 @@ https://github.com/mbutterick/restructure/blob/master/src/String.coffee
(decode-string len port encoding)
(pos port (+ (pos port) adjustment))))
(define/augment (xxencode val-arg port [parent #f])
(define/augment (x:encode val-arg port [parent #f])
(define val (if (string? val-arg) val-arg (format "~a" val-arg)))
(define encoding (if (procedure? @encoding)
(or (@encoding (and parent (dict-ref parent val)) 'ascii))
@ -58,11 +58,11 @@ https://github.com/mbutterick/restructure/blob/master/src/String.coffee
(when (and (exact-nonnegative-integer? @len) (> encoded-length @len))
(raise-argument-error 'xstring-encode (format "string no longer than ~a" @len) val))
(when (xint? @len)
(send @len xxencode encoded-length port parent))
(send @len x:encode encoded-length port parent))
(define string-terminator (if (not @len) (bytes 0) (bytes))) ; null terminated when no len
(bytes-append encoded-str string-terminator))
(define/augment (xxsize [val-arg #f] [parent #f])
(define/augment (x:size [val-arg #f] [parent #f])
(define val (cond
[(string? val-arg) val-arg]
[(not val-arg) #false]
@ -74,7 +74,7 @@ https://github.com/mbutterick/restructure/blob/master/src/String.coffee
(define string-size (bytes-length (encode-string val encoding)))
(define strlen-size (cond
[(not @len) 1]
[(xint? @len) (send @len xxsize)]
[(xint? @len) (send @len x:size)]
[else 0]))
(+ string-size strlen-size)]
[else (resolve-length @len #f #:parent parent)]))))

@ -30,7 +30,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
([(key type) (in-dict fields)])
(define val (if (procedure? type)
(type sdr)
(send type xxdecode port sdr)))
(send type x:decode port sdr)))
(unless (void? val)
(dict-set! sdr key val))
(dict-set! sdr '_currentOffset (- (pos port) (dict-ref sdr '_startOffset)))
@ -53,7 +53,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
(when @fields (unless (dict? @fields)
(raise-argument-error '+xstruct "dict" @fields)))
(define/augride (xxdecode port parent [len 0])
(define/augride (x:decode port parent [len 0])
;; xstruct-setup and xstruct-parse-fields are separate to cooperate with VersionedStruct
(define decoded-hash
(xstruct-parse-fields port (xstruct-setup port parent len) @fields))
@ -62,9 +62,9 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
decoded-hash)
(define/override (decode port parent)
(dict->mutable-hash (xxdecode port parent)))
(dict->mutable-hash (x:decode port parent)))
(define/augride (xxencode val port [parent-arg #f])
(define/augride (x:encode val port [parent-arg #f])
;; check keys first, since `size` also relies on keys being valid
(unless (dict? val)
(raise-result-error 'xstruct-encode "dict" val))
@ -77,19 +77,19 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
'parent parent-arg
'val val
'pointerSize 0))
(dict-set! parent 'pointerOffset (+ (pos port) (xxsize val parent #f)))
(dict-set! parent 'pointerOffset (+ (pos port) (x:size val parent #f)))
(for ([(key type) (in-dict @fields)])
(send type xxencode (dict-ref val key) port parent))
(send type x:encode (dict-ref val key) port parent))
(for ([ptr (in-list (dict-ref parent 'pointers))])
(send (dict-ref ptr 'type) xxencode (dict-ref ptr 'val) port (dict-ref ptr 'parent))))
(send (dict-ref ptr 'type) x:encode (dict-ref ptr 'val) port (dict-ref ptr 'parent))))
(define/augride (xxsize [val #f] [parent-arg #f] [include-pointers #t])
(define/augride (x:size [val #f] [parent-arg #f] [include-pointers #t])
(define parent (mhasheq 'parent parent-arg
'val val
'pointerSize 0))
(define fields-size (for/sum ([(key type) (in-dict @fields)]
#:when (xenomorphic-type? type))
(send type xxsize (and val (dict-ref val key)) parent)))
(send type x:size (and val (dict-ref val key)) parent)))
(define pointers-size (if include-pointers (dict-ref parent 'pointerSize) 0))
(+ fields-size pointers-size))))

@ -35,7 +35,7 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
(raise-argument-error 'xversioned-struct-encode "valid version key" version))
(if (xstruct? field-object) (get-field fields field-object) field-object))
(define/override (xxdecode port parent [length 0])
(define/override (x:decode port parent [length 0])
(define res (xstruct-setup port parent length))
(dict-set! res 'version
(cond
@ -44,7 +44,7 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
(unless parent
(raise-argument-error 'xversioned-struct-decode "valid parent" parent))
(version-getter parent)]
[else (send @type xxdecode port)]))
[else (send @type x:decode port)]))
(when (dict-ref @versions 'header #f)
(xstruct-parse-fields port res (dict-ref @versions 'header)))
@ -54,11 +54,11 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
(raise-argument-error 'xversioned-struct-decode "valid version key" (cons version @versions))))
(cond
[(xversioned-struct? fields) (send fields xxdecode port parent)]
[(xversioned-struct? fields) (send fields x:decode port parent)]
[else (xstruct-parse-fields port res fields)
res]))
(define/override (xxencode encode-me port [parent-arg #f])
(define/override (x:encode encode-me port [parent-arg #f])
(unless (dict? encode-me)
(raise-argument-error 'xversioned-struct-encode "dict" encode-me))
(define parent (mhash 'pointers null
@ -66,23 +66,23 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
'parent parent-arg
'val encode-me
'pointerSize 0))
(dict-set! parent 'pointerOffset (+ (pos port) (xxsize encode-me parent #f)))
(dict-set! parent 'pointerOffset (+ (pos port) (x:size encode-me parent #f)))
(unless (or (symbol? @type) (procedure? @type))
(send @type xxencode (dict-ref encode-me 'version #f) port parent))
(send @type x:encode (dict-ref encode-me 'version #f) port parent))
(define maybe-header-dict (dict-ref @versions 'header #f))
(when maybe-header-dict
(for ([(key type) (in-dict maybe-header-dict)])
(send type xxencode (dict-ref encode-me key) port parent)))
(send type x:encode (dict-ref encode-me key) port parent)))
(define fields (extract-fields-dict encode-me))
(unless (andmap (λ (key) (member key (dict-keys encode-me))) (dict-keys fields))
(raise-argument-error 'xversioned-struct-encode (format "hash that contains superset of xversioned-struct keys: ~a" (dict-keys fields)) (hash-keys encode-me)))
(for ([(key type) (in-dict fields)])
(send type xxencode (dict-ref encode-me key) port parent))
(send type x:encode (dict-ref encode-me key) port parent))
(for ([ptr (in-list (dict-ref parent 'pointers))])
(send (dict-ref ptr 'type) xxencode (dict-ref ptr 'val) port (dict-ref ptr 'parent))))
(send (dict-ref ptr 'type) x:encode (dict-ref ptr 'val) port (dict-ref ptr 'parent))))
(define/override (xxsize [val #f] [parent-arg #f] [include-pointers #t])
(define/override (x:size [val #f] [parent-arg #f] [include-pointers #t])
(unless val
(raise-argument-error 'xversioned-struct-size "value" val))
(define parent (mhash 'parent parent-arg 'val val 'pointerSize 0))
@ -90,13 +90,13 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
(let ([struct-type @type])
(if (or (symbol? struct-type) (procedure? struct-type))
0
(send @type xxsize (dict-ref val 'version) parent))))
(send @type x:size (dict-ref val 'version) parent))))
(define header-size
(for/sum ([(key type) (in-dict (or (dict-ref @versions 'header #f) null))])
(send type xxsize (and val (dict-ref val key)) parent)))
(send type x:size (and val (dict-ref val key)) parent)))
(define fields-size
(for/sum ([(key type) (in-dict (extract-fields-dict val))])
(send type xxsize (and val (dict-ref val key)) parent)))
(send type x:size (and val (dict-ref val key)) parent)))
(define pointer-size (if include-pointers (dict-ref parent 'pointerSize) 0))
(+ version-size header-size fields-size pointer-size))))

Loading…
Cancel
Save