constructing example pasted by klgg on Mon Oct 22 10:26:43 2012

(bitpacket NString (size 8) (data (* 8 size) bitstring))
(define (make-nstr str)
  (let ((size (string-length str))
        (data str))
    (bitconstruct ((NString bitpacket)))))
(define nstr (make-nstr "ABC"))

multiple constructions pasted by klgg on Mon Oct 22 10:39:54 2012

(bitpacket TypeA (1) ("somedata" bitstring))
(bitpacket TypeB (2) ("anotherdata bitstring))

(define make-type (type)
 (bitconstruct
   ((TypeA))
   ((TypeB))
   (else (error "invalid type")))

(define packetA (make-type 1))
(define packetB (make-type 2))

no title pasted by klgg on Mon Oct 22 10:46:02 2012

(bitpacket TypeA (type 8) (check (= type 1) ("somedata" bitstring))
(bitpacket TypeB (type 8) (check (= type 2) ("anotherdata" bitstring))

(define make-type (type)
 (bitconstruct
   ((TypeA))
   ((TypeB))
   (else (error "invalid type")))

(define packetA (make-type 1)) ; result "\x01somedata"
(define packetB (make-type 2)) ; result "\x02anotherdata"

perhaps like that added by DerGuteMoritz on Mon Oct 22 10:50:21 2012

(define make-type (type)
  (bitconstruct
   ((TypeA type))
   ((TypeB type))
   (else (error "invalid type"))))