I think all this works ok. I've enclosed an example interaction from
the docs, which I've just extended to evolve `fish` in addition to
`aq`.

So, it's all implemented, and I can push if it seems like an ok
interface...

At Tue, 7 Jun 2016 17:14:54 +0200, Berthold Bäuml wrote:
> Sorry, I did not think this through completely. Serialization of cstructs, as 
> it is currently implemented, loses all “sub-structure” for non-pointer 
> content, correct? 
> 
> But wouldn’t because of this lost sub-structure your alternative 
> compatibility 
> protocol also fail when it comes to hierarchically embedded structs where 
> deep 
> down in the hierarchy a new version of a struct should be used?
> 
> 
> (define-serializable-cstruct _pond ([depth _float]))
> (define-serializable-cstruct _forrest ([a_pond _pond]))
> 
> and then a new version:
> (define-serializable-cstruct _old-pond ([depth _float]))
> (define-serializable-cstruct _pond ([num-fish _int]
>                                    [depth _float])
> 
> (define-serializable-cstruct _forrest ([a_pond _pond]))
> 
> So, the version of _forrest does not change and, hence, there is no way to 
> deserialize the correct, new version of the _pond.
> 
> I think this could only be resolved by changing the serialization so that it 
> keeps all relevant information also for non-pointer content.
> 
> Berthold
> > On 06 Jun 2016, at 19:22, Matthew Flatt <mfl...@cs.utah.edu> wrote:
> > 
> > Yes, but I think a different protocol will be needed than for
> > `serializable-struct`.
> > 
> > With
> > 
> > (serializable-struct pond (depth))
> > 
> > it's clear that the deserializer receives a single value for the single
> > field (or, more generally, N values for N fields). So, it's clear how
> > to make a compatibility deserialization function:
> > 
> > (serializable-struct/versions pond 1 (num-fish depth)
> >   ([0 (lambda (d) (pond 0 d))
> >       (lambda () ....)]))
> > 
> > With 
> > 
> >  (define-serializable-cstruct _pond ([depth _float]))
> > 
> > the deserializer internally deals with a byte-string representation of
> > non-pointer content plus a structured representation of pointer
> > content. We probably don't want to expose those details, and you don't
> > want to deal with them.
> > 
> > An alternative it to make the compatibility protocol work in terms of a
> > separate cstruct declaration:
> > 
> > (define-serializable-cstruct _old-pond ([depth _float]))
> > 
> > (define-serializable-cstruct _pond ([num-fish _int]
> >                                     [depth _float])
> >   #:version 1
> >   #:other-versions ([0 deserialize-chain:cstruct:old-pond
> >                        (lambda (op)
> >                          (make-pond 0 (old-pond-depth op)))
> >                        (lambda () ....)]))
> > 
> > That is, compatibility deserialization is based on a reference to
> > deserialization information for a cstruct that has the same shape as
> > the old version, plus converters from instances of the old shape to the
> > new cstruct.
> > 
> > Does that interface seem ok?
> > 
> > 
> > At Sun, 5 Jun 2016 22:04:23 +0200, Berthold Bäuml wrote:
> >> Would it be possible to add for the serializable cstruct 
> >> (define-serializable-cstruct) versioning like in 
> >> define-serializable-struct/versions?
> >> 
> >> Berthold
> >> 
> >> -- 
> >> -----------------------------------------------------------------------
> >> Berthold Bäuml -- Head of Autonomous Learning Robots Lab
> >> DLR, Robotics and Mechatronics Center (RMC)
> >> Münchner Str. 20, D-82234 Wessling
> >> Phone +49 8153 282489
> >> http://www.robotic.de/Berthold.Baeuml
> >> 
> >> -- 
> >> You received this message because you are subscribed to the Google Groups 
> >> "Racket Users" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an 
> >> email to racket-users+unsubscr...@googlegroups.com.
> >> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> -----------------------------------------------------------------------
> Berthold Bäuml -- Head of Autonomous Learning Robots Lab
> DLR, Robotics and Mechatronics Center (RMC)
> Münchner Str. 20, D-82234 Wessling
> Phone +49 8153 282489
> http://www.robotic.de/Berthold.Baeuml
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
> (define-serializable-cstruct fish ([color _int]))
> (define f0/s (serialize (make-fish 1)))
> (fish-color (deserialize f0/s))
1
> (define-serializable-cstruct aq ([a fish-pointer]
                                   [d aq-pointer/null])
    #:malloc-mode 'nonatomic)
> (define aq1 (make-aq/mode (make-fish 6) #f))
> (set-aq-d! aq1 aq1) ; create a cycle
> (define aq0/s (serialize aq1))
> (aq-a (aq-d (aq-d (deserialize aq0/s))))
#<cpointer:fish>
; Same shape as original aq:
> (define-serializable-cstruct old-aq ([a fish-pointer]
                                       [d _pointer])
          #:malloc-mode 'nonatomic)
; Replace the original aq:
> (define-serializable-cstruct aq ([a fish-pointer]
                                   [b fish-pointer]
                                   [d aq-pointer/null])
    #:malloc-mode 'nonatomic
    #:version 1
    #:other-versions ([0 deserialize-chain:cstruct:old-aq
                         (lambda (oa)
                           (make-aq/mode (old-aq-a oa)
                                         (old-aq-a oa)
                                         (cast (old-aq-d oa) _pointer 
aq-pointer)))
                         (lambda (a)
                           (make-old-aq/mode (aq-a a)
                                             (aq-d a)))
                         (lambda ()
                           (define tmp-fish (make-fish 0))
                           (define a (make-aq/mode tmp-fish tmp-fish #f))
                           (values a
                                   (lambda (oa)
                                     (set-aq-a! a (old-aq-a oa))
                                     (set-aq-b! a (old-aq-a oa))
                                     (set-aq-d! a (cast (old-aq-d oa) _pointer 
aq-pointer)))))]))
; Deserialize old instance to new cstruct:
> (fish-color (aq-a (aq-d (aq-d (deserialize aq0/s)))))
6
> (define aq1/s (serialize (make-aq (make-fish 1) (make-fish 2) #f)))
; New version of fish:
> (define-serializable-cstruct old-fish ([color _int]))
> (define-serializable-cstruct fish ([weight _float]
                                     [color _int])
    #:version 1
    #:other-versions ([0 deserialize-chain:cstruct:old-fish
                         (lambda (of)
                           (make-fish 10.0 (old-fish-color of)))
                         (lambda (a) (error "cycles not possible!"))
                         (lambda () (error "cycles not possible!"))]))
; Deserialized content upgraded to new fish:
> (fish-color (aq-b (deserialize aq1/s)))
2
> (fish-weight (aq-b (deserialize aq1/s)))
10.0

Reply via email to