main
Matthew Butterick 6 years ago
parent e456116dee
commit fa97961eb1

@ -1,4 +1,4 @@
#lang debug racket/base
#lang racket/base
(require racket/dict
racket/class
racket/sequence
@ -98,7 +98,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
[len (or len-arg len-kwarg)]
[length-type (if count-bytes? 'bytes length-type-arg)]))
(define (xarray? x) (is-a? x x:array%))
(define (x:array? x) (is-a? x x:array%))
(module+ test
(require rackunit "generic.rkt")

@ -1,4 +1,4 @@
#lang debug racket/base
#lang racket/base
(require racket/private/generic-methods
racket/dict
racket/port

@ -1,4 +1,4 @@
#lang debug racket/base
#lang racket/base
(require racket/class
"helper.rkt" "util.rkt" "number.rkt" "array.rkt" racket/stream sugar/unstable/dict)
(provide (all-defined-out))

@ -1,4 +1,4 @@
#lang debug racket/base
#lang racket/base
(require "helper.rkt" racket/class)
(provide (all-defined-out))

@ -1,4 +1,4 @@
#lang debug racket/base
#lang racket/base
(require "helper.rkt" racket/class)
(provide (all-defined-out))

@ -1,4 +1,4 @@
#lang debug racket/base
#lang racket/base
(require "helper.rkt"
"number.rkt"
racket/dict

@ -1,4 +1,4 @@
#lang debug racket/base
#lang racket/base
(require racket/class racket/dict "helper.rkt" "util.rkt" "number.rkt")
(provide (all-defined-out))

@ -1,4 +1,4 @@
#lang debug racket/base
#lang racket/base
(require racket/dict
racket/class
racket/sequence
@ -23,7 +23,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
mheq)
(define (xstruct-parse-fields port sdr fields-arg)
(define fields (if (xstruct? fields-arg) (get-field fields fields-arg) fields-arg))
(define fields (if (x:struct? fields-arg) (get-field fields fields-arg) fields-arg))
(unless (assocs? fields)
(raise-argument-error 'xstruct-parse-fields "assocs" fields))
(for/fold ([sdr sdr])
@ -93,7 +93,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
(define pointers-size (if include-pointers (dict-ref parent 'pointerSize) 0))
(+ fields-size pointers-size))))
(define (xstruct? x) (is-a? x x:struct%))
(define (x:struct? x) (is-a? x x:struct%))
(define (x:struct #:pre-encode [pre-proc #f]
#:post-decode [post-proc #f] . dicts)

@ -30,7 +30,7 @@ https://github.com/mbutterick/restructure/blob/master/test/LazyArray.coffee
(parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))])
(define xla (x:lazy-array uint8 4 #:post-decode (λ (str) (stream-map (λ (i) (* 2 i)) str))))
(define arr (decode xla))
(check-false (xarray? arr))
(check-false (x:array? arr))
(check-equal? (stream-length arr) 4)
(check-equal? (pos (current-input-port)) 4)
(check-equal? (stream-ref arr 0) 2)

@ -1,4 +1,4 @@
#lang debug racket/base
#lang racket/base
(require rackunit
racket/dict
racket/class

@ -1,4 +1,4 @@
#lang debug racket/base
#lang racket/base
(require rackunit racket/dict
racket/class
"../helper.rkt"

@ -1,4 +1,4 @@
#lang debug racket/base
#lang racket/base
(require rackunit
racket/dict
sugar/unstable/dict

@ -1,4 +1,4 @@
#lang debug racket/base
#lang racket/base
(require "helper.rkt" "struct.rkt"
racket/dict
racket/class
@ -18,7 +18,7 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
(unless (for/or ([proc (list integer? procedure? xenomorphic-type? symbol?)])
(proc @type))
(raise-argument-error '+xversioned-struct "integer, procedure, symbol, or xenomorphic" @type))
(unless (and (dict? @versions) (andmap (λ (v) (or (dict? v) (xstruct? v))) (dict-values @versions)))
(unless (and (dict? @versions) (andmap (λ (v) (or (dict? v) (x:struct? v))) (dict-values @versions)))
(raise-argument-error '+xversioned-struct "dict of dicts or structish" @versions))
(define version-getter (cond
@ -33,7 +33,7 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
(define field-object (dict-ref @versions (dict-ref val 'version #f) #f))
(unless field-object
(raise-argument-error 'xversioned-struct-encode "valid version key" version))
(if (xstruct? field-object) (get-field fields field-object) field-object))
(if (x:struct? field-object) (get-field fields field-object) field-object))
(define/override (x:decode port parent [length 0])
(define res (xstruct-setup port parent length))
@ -54,7 +54,7 @@ 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 x:decode port parent)]
[(x:versioned-struct? fields) (send fields x:decode port parent)]
[else (xstruct-parse-fields port res fields)
res]))
@ -100,7 +100,7 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
(define pointer-size (if include-pointers (dict-ref parent 'pointerSize) 0))
(+ version-size header-size fields-size pointer-size))))
(define (xversioned-struct? x) (is-a? x x:versioned-struct%))
(define (x:versioned-struct? x) (is-a? x x:versioned-struct%))
(define (x:versioned-struct type [versions (dictify)]
#:pre-encode [pre-proc #f]

Loading…
Cancel
Save