xenobase% → x:base%

main
Matthew Butterick 6 years ago
parent e3f4d88f8f
commit 88e5267f09

@ -12,7 +12,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
|#
(define x:array%
(class xenobase%
(class x:base%
(super-new)
(init-field [(@type type)] [(@len len)] [(@count-bytes? count-bytes?)])

@ -1,5 +1,5 @@
#lang racket/base
(require racket/class)
(require racket/class racket/match)
(provide (all-defined-out))
(struct x:ptr (type val parent) #:transparent)
@ -45,7 +45,7 @@
(define (size xo [val #f] #:parent [parent #f])
(send xo size val parent))
(define (xenomorphic-type? x) (is-a? x xenobase%))
(define (xenomorphic-type? x) (is-a? x x:base%))
(define xenomorphic? xenomorphic-type?)
(define-syntax-rule (generate-subclass CLASS PRE-ENCODE-PROC POST-DECODE-PROC)
@ -65,7 +65,7 @@
(define/override (post-decode x) (POST-DECODE-PROC (super post-decode x))))]
[else CLASS]))
(define xenobase%
(define x:base%
(class object%
(super-new)
@ -73,14 +73,14 @@
(post-decode (inner (error 'decode-not-augmented) decode input-port parent)))
(define/pubment (encode val output-port [parent #f])
(define encode-result (inner (error 'encode-not-augmented) encode (pre-encode val) output-port parent))
(when (bytes? encode-result) (write-bytes encode-result output-port)))
(match (inner (error 'encode-not-augmented) encode (pre-encode val) output-port parent)
[(? bytes? encode-result) (write-bytes encode-result output-port)]
[_ (void)]))
(define/pubment (size [val #f] [parent #f] . args)
(define asize (inner 0 size val parent . args))
(unless (and (integer? asize) (not (negative? asize)))
(raise-argument-error 'size "nonnegative integer" asize))
asize)
(match (inner 0 size val parent . args)
[(? exact-nonnegative-integer? size) size]
[other (raise-argument-error 'size "nonnegative integer" other)]))
(define/public (post-decode val) val)
(define/public (pre-encode val) val)))

@ -8,7 +8,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Bitfield.coffee
|#
(define x:bitfield%
(class xenobase%
(class x:base%
(super-new)
(init-field [(@type type)][(@flags flags)])
(unless (andmap (λ (f) (or (symbol? f) (not f))) @flags)

@ -8,7 +8,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Buffer.coffee
|#
(define x:buffer%
(class xenobase%
(class x:base%
(super-new)
(init-field [(@len len)])
(unless (length-resolvable? @len)

@ -8,7 +8,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Enum.coffee
|#
(define x:enum%
(class xenobase%
(class x:base%
(super-new)
(init-field [(@type type)] [(@values values)])

@ -24,7 +24,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Number.coffee
(define system-endian (if (system-big-endian?) 'be 'le))
(define x:number%
(class xenobase%
(class x:base%
(super-new)
(init-field [(@size size)] [(@endian endian)])

@ -8,7 +8,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Optional.coffee
|#
(define x:optional%
(class xenobase%
(class x:base%
(super-new)
(init-field [(@type type)] [(@condition condition)])

@ -24,7 +24,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
[else (raise-argument-error 'x:pointer "VoidPointer" val)]))
(define x:pointer%
(class xenobase%
(class x:base%
(super-new)
(init-field [(@offset-type offset-type)]
[(@type type)]
@ -113,7 +113,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
[null-value null-value]))
;; A pointer whose type is determined at decode time
(define x:void-pointer% (class xenobase%
(define x:void-pointer% (class x:base%
(super-new)
(init-field type value)))
(define (x:void-pointer . args) (apply make-object x:void-pointer% args))

@ -8,7 +8,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Reserved.coffee
|#
(define x:reserved%
(class xenobase%
(class x:base%
(super-new)
(init-field [(@type type)] [(@count count)])

@ -29,7 +29,7 @@ https://github.com/mbutterick/restructure/blob/master/src/String.coffee
(not (eof-object? (peek-byte port))))
(define x:string%
(class xenobase%
(class x:base%
(super-new)
(init-field [(@len len)] [(@encoding encoding)])

@ -44,7 +44,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
h)
(define x:struct%
(class xenobase%
(class x:base%
(super-new)
(init-field [(@fields fields)])

Loading…
Cancel
Save