main
Matthew Butterick 6 years ago
parent 48a3307754
commit d3497402b2

@ -114,10 +114,10 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
x:list?)
(define type (or type-arg type-kwarg))
(unless (xenomorphic? type)
(raise-argument-error x:list "xenomorphic type" type))
(raise-argument-error 'x:list "xenomorphic type" type))
(define len (or len-arg len-kwarg))
(unless (length-resolvable? len)
(raise-argument-error x:list "resolvable length" len))
(raise-argument-error 'x:list "resolvable length" len))
(new (generate-subclass base-class pre-proc post-proc)
[type type]
[len len]

@ -61,10 +61,10 @@ https://github.com/mbutterick/restructure/blob/master/src/LazyArray.coffee
x:stream?)
(define type (or type-arg type-kwarg))
(unless (xenomorphic? type)
(raise-argument-error x:stream "xenomorphic type" type))
(raise-argument-error 'x:stream "xenomorphic type" type))
(define len (or len-arg len-kwarg))
(unless (length-resolvable? len)
(raise-argument-error x:stream "resolvable length" len))
(raise-argument-error 'x:stream "resolvable length" len))
(new (generate-subclass base-class pre-proc post-proc) [type type]
[len len]
[count-bytes? #false]))

@ -1,5 +1,6 @@
#lang debug racket/base
(require racket/class
racket/contract
"base.rkt"
"number.rkt"
"util.rkt"
@ -18,19 +19,39 @@
(define/override (post-decode val) (list->vector val))))
(define (x:vector [type-arg #f] [len-arg #f] [length-type-arg 'count]
#:type [type-kwarg #f]
#:length [len-kwarg #f]
#:count-bytes [count-bytes? #f]
#:pre-encode [pre-proc #f]
#:post-decode [post-proc #f]
#:base-class [base-class x:vector%])
(new (generate-subclass base-class pre-proc post-proc) [type (or type-arg type-kwarg)]
[len (or len-arg len-kwarg)]
[count-bytes? count-bytes?]))
(define (x:vector? x) (is-a? x x:vector%))
(define/contract (x:vector
[type-arg #f]
[len-arg #f]
#:type [type-kwarg #f]
#:length [len-kwarg #f]
#:count-bytes [count-bytes? #f]
#:pre-encode [pre-proc #f]
#:post-decode [post-proc #f]
#:base-class [base-class x:vector%])
(()
((or/c xenomorphic? #false)
(or/c length-resolvable? #false)
#:type (or/c xenomorphic? #false)
#:length (or/c length-resolvable? #false)
#:count-bytes boolean?
#:pre-encode (or/c (any/c . -> . any/c) #false)
#:post-decode (or/c (any/c . -> . any/c) #false)
#:base-class (λ (c) (subclass? c x:vector%)))
. ->* .
x:vector?)
(define type (or type-arg type-kwarg))
(unless (xenomorphic? type)
(raise-argument-error 'x:vector "xenomorphic type" type))
(define len (or len-arg len-kwarg))
(unless (length-resolvable? len)
(raise-argument-error 'x:vector "resolvable length" len))
(new (generate-subclass base-class pre-proc post-proc)
[type type]
[len len]
[count-bytes? count-bytes?]))
(module+ test
(require rackunit)
(check-equal? (decode (x:vector uint16be 3) #"ABCDEF") '#(16706 17220 17734))

Loading…
Cancel
Save