-- S.MG, 2018 -- prototype implementation of S.MG communication protocol with Ada.Streams; use Ada.Streams; with Interfaces; use Interfaces; -- Integer_n and Unsigned_n with Ada.Unchecked_Conversion; -- converting int/uint to array of octets package SMG_comms_types is -- basic types with guaranteed lengths type Octet_Array is array(Natural range <>) of Unsigned_8; subtype Octets_1 is Octet_Array( 1 .. 1 ); subtype Octets_2 is Octet_Array( 1 .. 2 ); subtype Octets_4 is Octet_Array( 1 .. 4 ); subtype Octets_8 is Octet_Array( 1 .. 8 ); subtype Message is Octet_Array( 1 .. 512 ); subtype RSAMessage is Octet_Array( 1 .. 245 ); -- blind, unchecked casts ( memcpy style ) function Cast is new Ada.Unchecked_Conversion( Integer_8, Octets_1 ); function Cast is new Ada.Unchecked_Conversion( Octets_1, Integer_8 ); function Cast is new Ada.Unchecked_Conversion( Integer_16, Octets_2 ); function Cast is new Ada.Unchecked_Conversion( Octets_2, Integer_16 ); function Cast is new Ada.Unchecked_Conversion( Integer_32, Octets_4 ); function Cast is new Ada.Unchecked_Conversion( Octets_4, Integer_32 ); function Cast is new Ada.Unchecked_Conversion( Integer_64, Octets_8 ); function Cast is new Ada.Unchecked_Conversion( Octets_8, Integer_64 ); -- to and from streams for network communications - general procedure ToNetworkFormat( Item : in Octet_Array; Buffer : out Stream_Element_Array); procedure FromNetworkFormat( Buffer : in Stream_Element_Array; Item : out Octet_Array); -- specific, convenience methods for the basic types -- Integer_8 procedure ToNetworkFormat( Item : in Integer_8; Buffer : out Stream_Element_Array); procedure FromNetworkFormat( Buffer : in Stream_Element_Array; Item : out Integer_8); end SMG_comms_types;