Gem #19: XML streaming of Ada objects Author: Pascal Obry, EDF R&D Abstract: Ada Gem #19 XML streaming of Ada objects Let s get started ¦ Since Ada 95 it has been possible to stream any object. Using 'Input/'Output or 'Read/'Write attributes, any object (tagged or not) can be streamed using a binary representation. This means that objects can be written into a file or sent over a socket, for example. Let s take a simple object hierarchy to illustrate this feature. We ll have a Point (x and y coordinate) and a Pixel (a Point with a color). package Object is type Point is tagged record X, Y : Float; end record; type Color_Name is (Red, Green, Blue); type Pixel is new Point with record Color : Color_Name; end record; end Object; When writing a Point or a Pixel the first bytes in the stream are the tag external representation then the object s attribute values. declare File : File_Type; P : Point'Class := ...; begin Create (File, Out_File, "streamed.data"); Point'Class'Output (Text_Streams.Stream (File), P); Close (File); end; The stream will contain something like (where is the character hexadecimal code): <01> <00> <00> <00> <0C> <00> <00>
/lp/association-for-computing-machinery/gem-19-xml-streaming-of-ada-objects-7rNDqzc4Xo