(*
    Title: 	Marshalling code
    LastEdit:	"Tue Jan  5 17:35:13 1988"
    Author: 	Derek McAuley,Oms1,4663,329629
		Cambridge University Computer Laboratory
*)

DEFINITION MODULE Marshal;


IMPORT
  PktBufs, RPCBasics;

FROM SystemTypes IMPORT String;
FROM SYSTEM      IMPORT ADDRESS, WORD;


EXPORT QUALIFIED 
  T, TR,
  
  New, Start, EndOfArgs, Discard,
  
  AWord, AChar, Words, Chars, AString, AnArrayOfWord, AnArrayOfChar, 
  ValueWord, UnWord;
  

TYPE
  T = POINTER TO TR;
  TR = 
    RECORD
      ptr,
      end:       CARDINAL;
      marshal,
      swapEndian:BOOLEAN;
      iPktBuf,            (* First PktBuf *)
      cPktBuf:   PktBufs.T;  (* Current PktBufs.T *)
    END;

PROCEDURE New(p:PktBufs.T):T;

PROCEDURE Start(m:T);

PROCEDURE EndOfArgs(m:T):BOOLEAN;

PROCEDURE Discard(m:T);


PROCEDURE AWord(VAR x:WORD; m:T);

PROCEDURE AChar(VAR c:CHAR; m:T);

PROCEDURE Words(start:ADDRESS; n:CARDINAL; m:T);

PROCEDURE Chars(start:ADDRESS; n:CARDINAL; m:T);

PROCEDURE AString(VAR x:String; m:T);

PROCEDURE AnArrayOfWord(
  VAR x:ARRAY OF WORD;
  VAR n:CARDINAL;
      m:T
 );
  (* For   marshalling:n is (* In *)  - marshal Min(n, max)
         unmarshalling:n is (* Out *) - elements unmarshalled.   
  *)

PROCEDURE AnArrayOfChar(
  VAR x:ARRAY OF CHAR;
  VAR n:CARDINAL;
      m:T
 );
  (* For   marshalling:n is (* In *)  - marshal Min(n, max)
         unmarshalling:n is (* Out *) - elements unmarshalled.   
  *)

PROCEDURE ValueWord(x:WORD; m:T);

PROCEDURE UnWord(m:T):WORD;

END Marshal.
