XNSCHItemOps.mesa
Copyright Ó 1988, 1991 by Xerox Corporation. All rights reserved.
Wes Irish, November 15, 1988 11:32:45 am PST
DIRECTORY
Rope USING [ROPE],
XNS USING [Address],
XNSCH USING [Item, Name];
For marshaling and unmarshaling XNSCH.Item.
XNSCHItemOps: CEDAR DEFINITIONS =
BEGIN
ROPE: TYPE = Rope.ROPE;
Name: TYPE = XNSCH.Name;
Address: TYPE = XNS.Address;
Item: TYPE = XNSCH.Item;
RopeList: TYPE = LIST OF ROPE;
NameList: TYPE = LIST OF Name;
AddressList: TYPE = LIST OF Address;
Some sample usages:
To Unmarshal an Item that represents an XNSCH.Name:
name: XNSCH.Name ← XNSCHItemOps.NameFromItem[item].name;
To Create an Item containing a list of ropes:
item ← XNSCHItemOps.ItemFromRopeList[LIST["First Rope", "Second Rope", "Etc..."]].item
To Unmarshal the above example:
ropeList: XNSCHItemOps.RopeList ← XNSCHItemOps.RopeListFromItem[item].ropes
To Unmarshal an Item that represents a RECORD:
mailboxInfo: RECORD [
time: CARD32,
mailboxList: NameList
];
pos: CARDINAL;
[mailboxInfo.time, pos] ← XNSCHItemOps.Card32FromItem[item, 0];
[mailboxInfo.mailboxList, pos] ← XNSCHItemOps.NameListFromItem[item, pos];
-- or, if you are only interested in the mailboxList:
mailboxList: NameList ← XNSCHItemOps.NameListFromItem[item, XNSCHItemOps.SizeOfCard32[]].names;
Errors
Error: ERROR [reason: ErrorType];
ErrorType: TYPE = { itemLength };
Unmarshaling PROCs
These PROCs take an Item and a starting index and return the unmarshaled data and the nextPos (where the next marshaled data should start). nextPos is normally used as the index to the next call within the same Item. nextPos >= item.length when you have exhausted the item.
Will raise Error[itemLength] if unmarshaling runs off the end of the item.
BoolFromItem: PROC [item: Item, index: CARDINAL ¬ 0] RETURNS [bool: BOOL, nextPos: CARDINAL];
Int16FromItem: PROC [item: Item, index: CARDINAL ¬ 0] RETURNS [int: INT16, nextPos: CARDINAL];
Int32FromItem: PROC [item: Item, index: CARDINAL ¬ 0] RETURNS [int: INT32, nextPos: CARDINAL];
Card16FromItem: PROC [item: Item, index: CARDINAL ¬ 0] RETURNS [card: CARD16, nextPos: CARDINAL];
Card32FromItem: PROC [item: Item, index: CARDINAL ¬ 0] RETURNS [card: CARD32, nextPos: CARDINAL];
RopeFromItem: PROC [item: Item, index: CARDINAL ¬ 0] RETURNS [rope: ROPE, nextPos: CARDINAL];
NameFromItem: PROC [item: Item, index: CARDINAL ¬ 0] RETURNS [name: Name, nextPos: CARDINAL];
AddressFromItem: PROC [item: Item, index: CARDINAL ¬ 0] RETURNS [address: XNS.Address, nextPos: CARDINAL];
The following unmarshal a SEQUENCE of xxx from the Item into a LIST for Cedar.
RopeListFromItem: PROC [item: Item, index: CARDINAL ¬ 0] RETURNS [ropes: RopeList, nextPos: CARDINAL];
NameListFromItem: PROC [item: Item, index: CARDINAL ¬ 0] RETURNS [names: NameList, nextPos: CARDINAL];
AddressListFromItem: PROC [item: Item, index: CARDINAL ¬ 0] RETURNS [addresses: AddressList, nextPos: CARDINAL];
"Simple" Marshaling PROCs:
These PROCs take your data and optionally a starting index and item. They create newItem big enough to accomadate your new data and/or the original item. All data from the original item is copied to newItem. Next, your new data is marshaled into newItem starting at index returning newItem and nextPos. nextPos is normally used as the index to the next call within the same Item.
Will NOT raise Error[itemLength] since a new item is created of the needed size.
ItemFromBool: PROC [bool: BOOL, index: CARDINAL ¬ 0, item: Item ¬ NIL] RETURNS [newItem: Item, nextPos: CARDINAL];
ItemFromInt16: PROC [int: INT16, index: CARDINAL ¬ 0, item: Item ¬ NIL] RETURNS [newItem: Item, nextPos: CARDINAL];
ItemFromInt32: PROC [int: INT32, index: CARDINAL ¬ 0, item: Item ¬ NIL] RETURNS [newItem: Item, nextPos: CARDINAL];
ItemFromCard16: PROC [card: CARD16, index: CARDINAL ¬ 0, item: Item ¬ NIL] RETURNS [newItem: Item, nextPos: CARDINAL];
ItemFromCard32: PROC [card: CARD32, index: CARDINAL ¬ 0, item: Item ¬ NIL] RETURNS [newItem: Item, nextPos: CARDINAL];
ItemFromAddress: PROC [address: Address, index: CARDINAL ¬ 0, item: Item ¬ NIL] RETURNS [newItem: Item, nextPos: CARDINAL];
ItemFromRope: PROC [rope: ROPE, index: CARDINAL ¬ 0, item: Item ¬ NIL] RETURNS [newItem: Item, nextPos: CARDINAL];
ItemFromName: PROC [name: Name, index: CARDINAL ¬ 0, item: Item ¬ NIL] RETURNS [newItem: Item, nextPos: CARDINAL];
ItemFromAddressList: PROC [addresses: AddressList, index: CARDINAL ¬ 0, item: Item ¬ NIL] RETURNS [newItem: Item, nextPos: CARDINAL];
ItemFromRopeList: PROC [ropes: RopeList, index: CARDINAL ¬ 0, item: Item ¬ NIL] RETURNS [newItem: Item, nextPos: CARDINAL];
ItemFromNameList: PROC [names: NameList, index: CARDINAL ¬ 0, item: Item ¬ NIL] RETURNS [newItem: Item, nextPos: CARDINAL];
The rest of the PROCs in this interface are utilities and/or for doing things more efficiently than making multiple calls to ItemFromXxx for "compound" items.
SizeOf PROCs
SizeOf... returns the number of (16 bit) words it would take to marshal the given data. This includes any overhead words, such as length information.
SizeOfBool: PROC RETURNS [size: CARDINAL];
SizeOfInt16: PROC RETURNS [size: CARDINAL];
SizeOfInt32: PROC RETURNS [size: CARDINAL];
SizeOfCard16: PROC RETURNS [size: CARDINAL];
SizeOfCard32: PROC RETURNS [size: CARDINAL];
SizeOfRope: PROC [rope: ROPE] RETURNS [size: CARDINAL];
SizeOfName: PROC [name: Name] RETURNS [size: CARDINAL];
SizeOfAddress: PROC RETURNS [size: CARDINAL];
SizeOfRopeList: PROC [ropes: RopeList] RETURNS [size: CARDINAL];
SizeOfNameList: PROC [names: NameList] RETURNS [size: CARDINAL];
SizeOfAddressList: PROC [addresses: AddressList] RETURNS [size: CARDINAL];
CreateNewItem: PROC [size: CARDINAL, index: CARDINAL ¬ 0, item: Item ¬ NIL] RETURNS [newItem: Item];
Creates a new Item of size MAX[oldLength, index+size], where oldLength is item.length or 0 if item is NIL.
The following follow the this model: you hand in an Item and a starting index and the PROC marshals your data and returns nextPos, that is where you should start your next marshaled data. nextPos is normally used as index to the next call within the same Item. nextPos >= item.length when you have filled the item.
Will raise Error[itemLength] if marshaling runs off the end of the item.
BoolIntoItem: PROC [item: Item, bool: BOOL, index: CARDINAL ¬ 0] RETURNS [nextPos: CARDINAL];
Int16IntoItem: PROC [item: Item, int: INT16, index: CARDINAL ¬ 0] RETURNS [nextPos: CARDINAL];
Int32IntoItem: PROC [item: Item, int: INT32, index: CARDINAL ¬ 0] RETURNS [nextPos: CARDINAL];
Card16IntoItem: PROC [item: Item, card: CARD16, index: CARDINAL ¬ 0] RETURNS [nextPos: CARDINAL];
Card32IntoItem: PROC [item: Item, card: CARD32, index: CARDINAL ¬ 0] RETURNS [nextPos: CARDINAL];
RopeIntoItem: PROC [item: Item, rope: ROPE, index: CARDINAL ¬ 0] RETURNS [nextPos: CARDINAL];
NameIntoItem: PROC [item: Item, name: Name, index: CARDINAL ¬ 0] RETURNS [nextPos: CARDINAL];
AddressIntoItem: PROC [item: Item, address: Address, index: CARDINAL ¬ 0] RETURNS [nextPos: CARDINAL];
RopeListIntoItem: PROC [item: Item, ropes: RopeList, index: CARDINAL ¬ 0] RETURNS [nextPos: CARDINAL];
NameListIntoItem: PROC [item: Item, names: NameList, index: CARDINAL ¬ 0] RETURNS [nextPos: CARDINAL];
AddressListIntoItem: PROC [item: Item, addresses: AddressList, index: CARDINAL ¬ 0] RETURNS [nextPos: CARDINAL];
END.