SerializedFiling.mesa
Copyright Ó 1989, 1991 by Xerox Corporation. All rights reserved.
Doug Terry, December 11, 1989 12:09:50 pm PST
Willie-Sue, March 21, 1990 11:48:21 am PST
Operations for parsing XNS serialized files and such. The serialized file format is defined in the XNS Filing protocol.
Willie-s, December 10, 1991 2:32 pm PST
~
BEGIN
ROPE: TYPE ~ Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
Error: ERROR [reason: ATOM, exp: ROPE];
Serialized file type
SerializedFile:
TYPE ~
RECORD [
version: CARD32,
file: SerializedTree
];
currentVersion: CARD32 ~ 3;
SerializedTree:
TYPE ~
RECORD [
attributes: AttributeSequence,
content: SerializedContentBytes,
children: SerializedTreeSequence
];
AttributeSequence: TYPE ~ REF AttributeSequenceObject;
AttributeSequenceObject:
TYPE ~
MACHINE
DEPENDENT
RECORD [
body: PACKED SEQUENCE length: CARDINAL OF Attribute
];
Attribute:
TYPE ~
RECORD [
type: AttributeType,
value: AttributeValue
];
AttributeType: TYPE ~ CARD32;
AttributeValue: TYPE ~ REF AttributeValueObject;
AttributeValueObject: TYPE ~ SegmentObject;
SerializedContentBytes:
TYPE ~
RECORD [
data: StreamOfUnspecified,
lastByteIsSignificant: BOOLEAN
];
StreamOfUnspecified: TYPE ~ LIST OF Segment;
Segment: TYPE ~ REF SegmentObject;
SegmentObject:
TYPE ~
MACHINE
DEPENDENT
RECORD [
body: PACKED SEQUENCE length: CARDINAL OF CARD16
];
SerializedTreeSequence: TYPE ~ REF SerializedTreeSequenceObject;
SerializedTreeSequenceObject:
TYPE ~
MACHINE
DEPENDENT
RECORD [
body: PACKED SEQUENCE length: CARDINAL OF SerializedTree
];
Reading/writing serialized files
GetSerializedFile:
PROC [s:
STREAM]
RETURNS [sfout: SerializedFile];
Reads a serialized file from the stream.
PutSerializedFile:
PROC [s:
STREAM, sfin: SerializedFile];
Writes a serialized file to the stream.
Useful extractors, conversions, etc.
GetRopeContents:
PROC [sf: SerializedFile]
RETURNS [contents:
ROPE];
Returns the contents of the serialized file as a rope.
SetRopeContents:
PROC [sf: SerializedFile, contents:
ROPE]
RETURNS [new: SerializedFile];
Sets the contents of the serialized file.
GetAttributeAsRope:
PROC [sf: SerializedFile, type: AttributeType]
RETURNS [value:
ROPE];
Finds an attribute of the given type and converts its value to a rope; returns NIL if no such attribute.
SetAttributeFromRope:
PROC [sf: SerializedFile, type: AttributeType, value:
ROPE]
RETURNS [new: SerializedFile];
Sets the value of the given attribute; Raises Error if the rope does not contain an even number of bytes (serialized file attributes must be an even number of bytes); does nothing if the serialized file does not contain an attribute of the specified type.
GetRopeAttribute:
PROC [sf: SerializedFile, type: AttributeType]
RETURNS [value:
ROPE];
Finds an attribute of the given type; uses CrRPC.GetRope.; returns NIL if no such attribute.
SetRopeAttribute:
PROC [sf: SerializedFile, type: AttributeType, value:
ROPE]
RETURNS [new: SerializedFile];
Sets the value of the given attribute, using CrRPC.PutRope;
does nothing if the serialized file does not contain an attribute of the specified type.
GetVersionedRopeAttribute:
PROC [sf: SerializedFile, type: AttributeType]
RETURNS [version:
CARD16, value:
ROPE];
Finds an attribute of the given type, the first CARD16 read is returned as version, the rest is read using CrRPC.GetRope; returns value = NIL if no such attribute.
SetVersionedRopeAttribute:
PROC [sf: SerializedFile, type: AttributeType, version:
CARD16, value:
ROPE]
RETURNS [new: SerializedFile];
Sets the value of the given attribute; first outputs version, then uses CrRPC.PutRope
does nothing if the serialized file does not contain an attribute of the specified type.
RopeFromSegment:
PROC [segment: Segment, lastByteIsSignificant:
BOOLEAN ¬
TRUE]
RETURNS [rope:
ROPE];
Converts a segment to a rope. Note: this also works for AttributeValues.
SegmentFromRope:
PROC [rope:
ROPE]
RETURNS [segment: Segment, lastByteIsSignificant:
BOOLEAN];
Converts a rope to a segment.