From 542d0a886a35d52c9da46d8586c50623f101e01a Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 21 Aug 2018 10:54:17 +0100 Subject: [PATCH] Explore struct inheritance --- syndicate/mc/codec.rkt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/syndicate/mc/codec.rkt b/syndicate/mc/codec.rkt index 3e49268..260dff1 100644 --- a/syndicate/mc/codec.rkt +++ b/syndicate/mc/codec.rkt @@ -320,4 +320,28 @@ (check-equal? (d (bytes version 131 2 0 0)) 131072) (check-equal? (d (bytes version #b11000010 #b00111111 #b10000000 0 0)) 1.0) (check-equal? (d (bytes version #b11000011 #b00111111 #b11110000 0 0 0 0 0 0)) 1.0) + + (struct date (year month day) #:prefab) + (struct thing (id) #:prefab) + (struct person thing (name date-of-birth) #:prefab) + (struct titled person (title) #:prefab) + + (check-equal? (encode (titled 101 "Blackwell" (date 1821 2 3) "Dr")) + (bytes version + #x35 ;; struct, generic, 4+1 + #x45 ;; list, 5 + #xb6 #x74 #x69 #x74 #x6c #x65 #x64 ;; symbol, "titled" + #xb6 #x70 #x65 #x72 #x73 #x6f #x6e ;; symbol, "person" + #x81 #x02 ;; integer, "2" + #xb5 #x74 #x68 #x69 #x6e #x67 ;; symbol, "thing" + #x81 #x01 ;; integer, "1" + #x81 #x65 ;; integer, "101" + #x99 #x42 #x6c #x61 #x63 #x6b #x77 #x65 #x6c #x6c ;; string, "Blackwell" + #x34 ;; struct, generic, 3+1 + #xb4 #x64 #x61 #x74 #x65 ;; symbol, "date" + #x82 #x07 #x1d ;; integer, "1821" + #x81 #x02 ;; integer, "2" + #x81 #x03 ;; integer, "3" + #x92 #x44 #x72 ;; string, "Dr" + )) )