From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 29 Jun 93 21:05:52 GMT From: emery@mitre-bedford.arpa (David Emery) Subject: Re: Retrieving Rep Spec'ed Enumeration Values Message-ID: List-Id: A much better way to handle this particular problem over the net is to use the 'POS/'VAL attributes, which are portable for all representations of the same enumeration type: shared code: package DEFINES_ENUM_TYPE is type COLOR is (RED, GREEN, BLUE): end DEFINES_ENUM_TYPE; package INTEGERS_OVER_NETWORK is procedure SEND (I : in INTEGER); procedure RECEIVE (I : out INTEGER); end INTEGERS_OVER_NETWORK; server/sender code: with INTEGERS_OVER_NETWORK; with DEFINES_ENUM_TYPE; procedure SEND_ENUM_VALUE (E : DEFINES_ENUM_TYPE.COLOR) is begin INTEGERS_OVER_NETWORK.SEND (DEFINES_ENUM_TYPE.COLOR'POS(E)); -- send the (integer) position (first, second, third enum value); end SEND_ENUM_VALUE; client/receiver code: with INTEGERS_OVER_NETWORK; with DEFINES_ENUM_TYPE; procedure RECEIVE_ENUM_VALUE (E : out DEFINES_ENUM_TYPE.COLOR) is I : INTEGER; begin INTEGERS_OVER_NETWORK.RECEIVE (I); if I in DEFINES_ENUM_TYPE.COLOR'POS (DEFINES_ENUM_TYPE.COLOR'FIRST)) .. DEFINES_ENUM_TYPE.COLOR'POS (DEFINES_ENUM_TYPE.COLOR'LAST)) then E := DEFINES_ENUM_TYPE.COLOR'VAL (I); else -- appropriate action for out of range value, e.g. raise -- exception, return default value, etc. end if; end RECEIVE_ENUM_VALUE; We have used this technique for sending enumeration types across Remote Procedure Calls. The SEND and RECEIVE operations were implemented using the ONC XDR xdr_int() operations (for which we have a simple Ada binding.) dave