-
+ A2253E5B8F18B3F3D7D9F7D0198761771470D53DC72986C9BE61B9809F101290F7DEF2F92970DD973E523E567A84375A25FFAE2C7A80F227AE49542B75F9B259
smg_comms/src/smg_comms_types.ads
(0 . 0)(1 . 52)
117 -- S.MG, 2018
118 -- prototype implementation of S.MG communication protocol
119
120 with Ada.Streams; use Ada.Streams;
121 with Interfaces; use Interfaces; -- Integer_n and Unsigned_n
122 with Ada.Unchecked_Conversion; -- converting int/uint to array of octets
123
124 package SMG_comms_types is
125 -- basic types with guaranteed lengths
126 type Octet_Array is array(Natural range <>) of Unsigned_8;
127
128 subtype Octets_1 is Octet_Array( 1 .. 1 );
129 subtype Octets_2 is Octet_Array( 1 .. 2 );
130 subtype Octets_4 is Octet_Array( 1 .. 4 );
131 subtype Octets_8 is Octet_Array( 1 .. 8 );
132
133 subtype Message is Octet_Array( 1 .. 512 );
134 subtype RSAMessage is Octet_Array( 1 .. 245 );
135
136 -- blind, unchecked casts ( memcpy style )
137 function Cast is new Ada.Unchecked_Conversion( Integer_8, Octets_1 );
138 function Cast is new Ada.Unchecked_Conversion( Octets_1, Integer_8 );
139
140 function Cast is new Ada.Unchecked_Conversion( Integer_16, Octets_2 );
141 function Cast is new Ada.Unchecked_Conversion( Octets_2, Integer_16 );
142
143 function Cast is new Ada.Unchecked_Conversion( Integer_32, Octets_4 );
144 function Cast is new Ada.Unchecked_Conversion( Octets_4, Integer_32 );
145
146 function Cast is new Ada.Unchecked_Conversion( Integer_64, Octets_8 );
147 function Cast is new Ada.Unchecked_Conversion( Octets_8, Integer_64 );
148
149 -- to and from streams for network communications - general
150 procedure ToNetworkFormat(
151 Item : in Octet_Array;
152 Buffer : out Stream_Element_Array);
153
154 procedure FromNetworkFormat(
155 Buffer : in Stream_Element_Array;
156 Item : out Octet_Array);
157
158 -- specific, convenience methods for the basic types
159 -- Integer_8
160 procedure ToNetworkFormat(
161 Item : in Integer_8;
162 Buffer : out Stream_Element_Array);
163
164 procedure FromNetworkFormat(
165 Buffer : in Stream_Element_Array;
166 Item : out Integer_8);
167
168 end SMG_comms_types;