• Automatic Serialization of Dynamic Structures in Ada

    From Manuel Gomez@21:1/5 to All on Fri Mar 4 21:26:21 2022
    I wanted to do automatic serialization of Ada types that make use of
    dynamic memory management with access types, but the standard solution
    only works for object values, not for access values. I've found a
    technical report describing a solution for that case, which apparently
    was implemented. Does anyone know if this tool is or were publicly
    available? Was an AI finally proposed as suggested in the Future Work?

    https://core.ac.uk/download/pdf/147904594.pdf

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to Manuel Gomez on Fri Mar 4 23:01:41 2022
    On 2022-03-04 21:26, Manuel Gomez wrote:
    I wanted to do automatic serialization of Ada types that make use of
    dynamic memory management with access types,

    That is impossible to do since the semantics of references access type implement is unknown. E.g. external references, references inside
    managed objects, references to non-movable, non-copyable objects,
    references created in certain order etc.

    I am using a method where references are either explicitly manifested by
    the serialized objects or explicitly converted to offsets by objects
    containing them.

    but the standard solution
    only works for object values, not for access values.

    If you mean stream attributes remember that they are non-portable and
    have very limited use unless overridden.

    Was an AI finally proposed as suggested in the Future Work?

    I doubt it could have practical use, e.g. for networking or persistence purposes.

    --
    Regards,
    Dmitry A. Kazakov
    http://www.dmitry-kazakov.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Matt Borchers@21:1/5 to All on Thu Mar 10 21:26:54 2022
    I'm not sure why Dmitry would say this is impossible unless you are actually talking about creating a generic package to serialize objects. Objects to a generic routine would be a black box so you would have to supply the serialization routines to the
    generic at instantiation. Otherwise, there are certainly cases that may prove impossible or challenging, but I think the OP is thinking of perhaps serializing simpler cases like a linked list, tree, or graph in memory. In this case, it is definitely
    possible even if the objects in the structure contain other dynamic elements.

    If you are serializing a structure where access type links are followed to do a simple traversal of the structure then you don't need distinct IDs for the objects that you are serializing. Otherwise, you probably do in order to fully regenerate the
    dynamic structure.

    My approach to this is to create a 'Read, 'Write, 'Input, and 'Output routines for both the access type and the type being accessed. I do this mostly for completeness, but it's not necessary if the program doesn't need both. You many not need a 'Read
    and 'Write, but if you need one then use 'Input and 'Output. There is a difference that should be obeyed for proper serialization: 'Output writes any necessary bounds of an array or other container type before writing the data and 'Input expects that
    bounds information to be available before reading the data. So, I generally have 'Output call 'Write and 'Input call 'Read to avoid duplication of code.

    The 'Output on the access type writes a Boolean value before the access value itself - True if not null. Then I write any boundary information necessary then invoke the 'Write on the .all of the access type. For 'Input, it would obviously read the
    Boolean value and if True read the boundary data and create a new instance of the expected type and then call 'Read to load data into the newly created .all object.

    For a linked list, tree, and even a complete graph a simple traversal works fine. For an incomplete graph, you may want to write out the nodes first and then write out coded information for how the nodes are linked so a reconstruction is possible from
    the input stream.

    This method even works for tagged types and the class-wide streaming routines that will rebuild the proper objects because the class-wide streaming routines stream the tag information about the object allowing dispatching on 'Class'Input (if I remember
    correctly).

    Regards,
    Matt

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)