@ -35,7 +35,7 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
( raise-argument-error ' xversioned-struct-encode " valid version key " version ) )
( if ( xstruct? field-object ) ( get-field fields field-object ) field-object ) )
( define/override ( x x decode port parent [ length 0 ] )
( define/override ( x : decode port parent [ length 0 ] )
( define res ( xstruct-setup port parent length ) )
( dict-set! res ' version
( cond
@ -44,7 +44,7 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
( unless parent
( raise-argument-error ' xversioned-struct-decode " valid parent " parent ) )
( version-getter parent ) ]
[ else ( send @type x x decode port ) ] ) )
[ else ( send @type x : decode port ) ] ) )
( when ( dict-ref @versions ' header #f )
( xstruct-parse-fields port res ( dict-ref @versions ' header ) ) )
@ -54,11 +54,11 @@ 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 x decode port parent ) ]
[ ( xversioned-struct? fields ) ( send fields x : decode port parent ) ]
[ else ( xstruct-parse-fields port res fields )
res ] ) )
( define/override ( x x encode encode-me port [ parent-arg #f ] )
( define/override ( x : encode encode-me port [ parent-arg #f ] )
( unless ( dict? encode-me )
( raise-argument-error ' xversioned-struct-encode " dict " encode-me ) )
( define parent ( mhash ' pointers null
@ -66,23 +66,23 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
' parent parent-arg
' val encode-me
' pointerSize 0 ) )
( dict-set! parent ' pointerOffset ( + ( pos port ) ( x x size encode-me parent #f ) ) )
( dict-set! parent ' pointerOffset ( + ( pos port ) ( x : size encode-me parent #f ) ) )
( unless ( or ( symbol? @type ) ( procedure? @type ) )
( send @type x x encode ( dict-ref encode-me ' version #f ) port parent ) )
( send @type x : encode ( dict-ref encode-me ' version #f ) port parent ) )
( define maybe-header-dict ( dict-ref @versions ' header #f ) )
( when maybe-header-dict
( for ( [ ( key type ) ( in-dict maybe-header-dict ) ] )
( send type x x encode ( dict-ref encode-me key ) port parent ) ) )
( send type x : encode ( dict-ref encode-me key ) port parent ) ) )
( define fields ( extract-fields-dict encode-me ) )
( unless ( andmap ( λ ( key ) ( member key ( dict-keys encode-me ) ) ) ( dict-keys fields ) )
( raise-argument-error ' xversioned-struct-encode ( format " hash that contains superset of xversioned-struct keys: ~a " ( dict-keys fields ) ) ( hash-keys encode-me ) ) )
( for ( [ ( key type ) ( in-dict fields ) ] )
( send type x x encode ( dict-ref encode-me key ) port parent ) )
( send type x : encode ( dict-ref encode-me key ) port parent ) )
( for ( [ ptr ( in-list ( dict-ref parent ' pointers ) ) ] )
( send ( dict-ref ptr ' type ) x x encode ( dict-ref ptr ' val ) port ( dict-ref ptr ' parent ) ) ) )
( send ( dict-ref ptr ' type ) x : encode ( dict-ref ptr ' val ) port ( dict-ref ptr ' parent ) ) ) )
( define/override ( x x size [ val #f ] [ parent-arg #f ] [ include-pointers #t ] )
( define/override ( x : size [ val #f ] [ parent-arg #f ] [ include-pointers #t ] )
( unless val
( raise-argument-error ' xversioned-struct-size " value " val ) )
( define parent ( mhash ' parent parent-arg ' val val ' pointerSize 0 ) )
@ -90,13 +90,13 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
( let ( [ struct-type @type ] )
( if ( or ( symbol? struct-type ) ( procedure? struct-type ) )
0
( send @type x x size ( dict-ref val ' version ) parent ) ) ) )
( send @type x : size ( dict-ref val ' version ) parent ) ) ) )
( define header-size
( for/sum ( [ ( key type ) ( in-dict ( or ( dict-ref @versions ' header #f ) null ) ) ] )
( send type x x size ( and val ( dict-ref val key ) ) parent ) ) )
( send type x : size ( and val ( dict-ref val key ) ) parent ) ) )
( define fields-size
( for/sum ( [ ( key type ) ( in-dict ( extract-fields-dict val ) ) ] )
( send type x x size ( and val ( dict-ref val key ) ) parent ) ) )
( send type x : size ( and val ( dict-ref val key ) ) parent ) ) )
( define pointer-size ( if include-pointers ( dict-ref parent ' pointerSize ) 0 ) )
( + version-size header-size fields-size pointer-size ) ) ) )