#### 8.2.1 Marshalling and Unmarshalling Operations

The Partition Communication Subsystem (PCS) is the runtime library for distributed features. It marshals and unmarshals client and server requests into a data stream suitable for network transmission.

Parameter streams are normally read and written using four attributes:

- Write: write an element into a stream, valid only for constrained types
- Read: read a constrained element from a stream
- Output: same as Write, but write discriminants or array bounds as well if needed
- Input: same as Read, but read discriminants or bounds from the stream (the Input attribute denotes a function)

An Ada compiler provides default 'Read and 'Write operations. But it is up to the implementation of the PCS to provide default 'Read and 'Write to ensure proper operation between heterogeneous architectures (see Heterogeneous System).

The user can override these operations, except for predefined types. Overriding with a custom version provides the user with a way to debug its application (even outside of the Distributed Systems Annex). On the other hand, remaining with the default implementation allows the user to take advantage of optimized and portable representations provided by the PCS.

         with Ada.Streams; use Ada.Streams;
         package New_Integers is
            pragma Pure;

            type New_Integer is new Integer;

            procedure Read
              (S : access Root_Stream_Type'Class;
               V : out New_Integer);
            procedure Write
              (S : access Root_Stream_Type'Class;
               V : in New_Integer);

            for New_Integer'Read  use Read;
            for New_Integer'Write use Write;
         end New_Integers;

         package body New_Integers is
            procedure Read
              (S : access Root_Stream_Type'Class;
               V : out New_Integer)
            is
               B : String := String'Input (S);
            begin
               V := New_Integer'Value (B);
            end Read;

            procedure Write
              (S : access Root_Stream_Type'Class;
               V : in New_Integer)
            is
            begin
               String'Output (S, New_Integer'Image (V));
            end Write;
         end New_Integers;

The language forces the user to provide Read and Write operations for non-remote access types. Transmitting an access value by dumping its content into a stream makes no sense when the value is going to be transmitted to another partition (with a different memory space). To transmit non-remote access types see Transmitting Dynamic Structure.