main
Matthew Butterick 6 years ago
parent ac885f26d0
commit c1464441c6

@ -68,7 +68,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
(send @len x:encode (length array) port) ; encode length at front
(encode-items new-parent)
(for ([ptr (in-list (hash-ref new-parent x:pointers-key))]) ; encode pointer data at end
(send (hash-ref ptr 'type) x:encode (hash-ref ptr x:val-key) port))]
(send (hash-ref ptr x:pointer-type-key) x:encode (hash-ref ptr x:val-key) port))]
[else (encode-items parent)]))
(define/augride (x:size [val #f] [parent #f])

@ -72,7 +72,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
(send @offset-type x:encode (- (hash-ref new-parent x:pointer-offset-key) relative) port)
(define-values (type val) (resolve-pointer @type val-in))
(hash-update! new-parent x:pointers-key
(λ (ptrs) (append ptrs (list (mhasheq 'type type x:val-key val x:parent-key parent)))))
(λ (ptrs) (append ptrs (list (mhasheq x:pointer-type-key type x:val-key val x:parent-key parent)))))
(hash-set! new-parent x:pointer-offset-key
(+ (hash-ref new-parent x:pointer-offset-key) (send type x:size val parent)))]
[else (send @offset-type x:encode @null-value port)]))

@ -114,7 +114,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
x:pointers-key null))
(encode (x:pointer) 10 #:parent parent)
(check-equal? (hash-ref parent x:pointer-offset-key) 2)
(check-equal? (hash-ref parent x:pointers-key) (list (mhasheq 'type uint8
(check-equal? (hash-ref parent x:pointers-key) (list (mhasheq x:pointer-type-key uint8
x:val-key 10
x:parent-key parent)))
(check-equal? (get-output-bytes (current-output-port)) (bytes 1))))
@ -128,7 +128,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
x:pointers-key null))
(encode (x:pointer #:relative-to 'immediate) 10 #:parent parent)
(check-equal? (hash-ref parent x:pointer-offset-key) 2)
(check-equal? (hash-ref parent x:pointers-key) (list (mhasheq 'type uint8
(check-equal? (hash-ref parent x:pointers-key) (list (mhasheq x:pointer-type-key uint8
x:val-key 10
x:parent-key parent)))
(check-equal? (get-output-bytes (current-output-port)) (bytes 0))))
@ -142,7 +142,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
x:pointers-key null)))
(encode (x:pointer #:relative-to 'parent) 10 #:parent parent)
(check-equal? (hash-ref* parent x:parent-key x:pointer-offset-key) 6)
(check-equal? (hash-ref* parent x:parent-key x:pointers-key) (list (mhasheq 'type uint8
(check-equal? (hash-ref* parent x:parent-key x:pointers-key) (list (mhasheq x:pointer-type-key uint8
x:val-key 10
x:parent-key parent)))
(check-equal? (get-output-bytes (current-output-port)) (bytes 2))))
@ -159,7 +159,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
(encode (x:pointer #:relative-to 'global) 10 #:parent parent)
(check-equal? (hash-ref* parent x:parent-key x:parent-key x:parent-key x:pointer-offset-key) 6)
(check-equal? (hash-ref* parent x:parent-key x:parent-key x:parent-key x:pointers-key)
(list (mhasheq 'type uint8
(list (mhasheq x:pointer-type-key uint8
x:val-key 10
x:parent-key parent)))
(check-equal? (get-output-bytes (current-output-port)) (bytes 5))))
@ -173,7 +173,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
x:pointers-key null))
(encode (x:pointer uint8 'void) (x:void-pointer uint8 55) #:parent parent)
(check-equal? (hash-ref parent x:pointer-offset-key) 2)
(check-equal? (hash-ref parent x:pointers-key) (list (mhasheq 'type uint8 x:val-key 55 x:parent-key parent)))
(check-equal? (hash-ref parent x:pointers-key) (list (mhasheq x:pointer-type-key uint8 x:val-key 55 x:parent-key parent)))
(check-equal? (get-output-bytes (current-output-port)) (bytes 1))))
(test-case

@ -82,7 +82,7 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
(for ([(key type) (in-dict fields)])
(send type x:encode (dict-ref encode-me key) port parent))
(for ([ptr (in-list (dict-ref parent x:pointers-key))])
(send (dict-ref ptr 'type) x:encode (dict-ref ptr x:val-key) port (dict-ref ptr x:parent-key))))
(send (dict-ref ptr x:pointer-type-key) x:encode (dict-ref ptr x:val-key) port (dict-ref ptr x:parent-key))))
(define/override (x:size [val #f] [parent-arg #f] [include-pointers #t])
(unless val

Loading…
Cancel
Save