ddat interop with dat js cable interop with cabal js ddat's frontend = dat-thang cable fe = cable-thang dillo support based on cel's dillo-dat bootstrap node xplatform support Signed-off-by: divo <418@cryspace.space>
32 lines
1.3 KiB
Scheme
32 lines
1.3 KiB
Scheme
;;; The C codec owns framing and protocol bytes. Scheme owns the readable view.
|
|
;;; Wire records have named fields, so optional fields can be added without
|
|
;;; changing positional call sites or the peer-visible protocol.
|
|
|
|
(define (dat:wire-message channel type payload)
|
|
(if (not (and (integer? channel) (exact? channel) (>= channel 0)))
|
|
(error 'out-of-range "wire channel must be a non-negative exact integer" channel))
|
|
(if (not (and (integer? type) (exact? type) (>= type 0)))
|
|
(error 'out-of-range "wire type must be a non-negative exact integer" type))
|
|
(if (not (byte-vector? payload))
|
|
(error 'wrong-type-arg "wire payload must be a bytevector" payload))
|
|
(list 'dat:wire-message
|
|
(cons 'channel channel)
|
|
(cons 'type type)
|
|
(cons 'payload payload)))
|
|
|
|
(define (dat:wire-message? value)
|
|
(and (dat:record? value 'dat:wire-message)
|
|
(integer? (dat:record-ref value 'channel #f))
|
|
(integer? (dat:record-ref value 'type #f))
|
|
(byte-vector? (dat:record-ref value 'payload #f))))
|
|
|
|
(define (dat:wire-frame->record bytes)
|
|
(dat-wire->sexp bytes))
|
|
|
|
(define (dat:record->wire-frame record)
|
|
(if (not (dat:wire-message? record))
|
|
(error 'wrong-type-arg "expected a dat:wire-message record" record)
|
|
(dat-sexp->wire record)))
|
|
|
|
(provide 'dat:wire)
|