Site Menu Project Specification Implementation Recommendations Reference Needs Updating Work in Progress Wastebasket Wiki Manual |
Serialised Scalar FormatSynopsisThe following describes an ASCII based serialisation format for numeric scalar values and conversion primitives to convert between numeric and serialised representation. ObjectivesThe serialised format needs to meet the following objectives:
Data FieldsA serialised scalar contains the following data fields:
[1] If the value of the exponent's digit count field is zero, then no exponent is encoded. Encoding of Numeric ValuesThe digits in an encoded digit stream appear in highest to lowest significance order and represent the roots of a polynom of the form: value = digit0 * radix n + digit1 * radix n-1 + digit2 * radix n-2 + ... + digitn-1 * radix 1 + digitn * radix 0
Base10 SerialisationBase10 serialisation is a radix 10 based ASCII encoding of numeric values. Digits are represented by the ASCII characters in the code point range from decimal 48 ("0") indicating 0, to decimal 57 ("9") indicating 9. Base16 SerialisationBase16 serialisation is a radix 16 based ASCII encoding of numeric values. Digits are represented by the ASCII characters in the code point range from decimal 48 ("0") indicating 0, to decimal 63 ("?") indicating 15. Base32 SerialisationBase32 serialisation is a radix 32 based ASCII encoding of numeric values. Digits are represented by the ASCII characters in the code point range from decimal 48 ("0") indicating 0, to decimal 79 ("O") indicating 31. EBNFserialisedScalarFormat : version length encoding sigDigitCount expDigitCount sigSign sigDigits ( expSign expDigits )? terminator ; version: digitB32 ; protocol version, at present the value is always 1 length : digitB32 digitB32 ; // allocated length, value between 8 and 1023 encoding : "D" | "H" ; // radix system, D for base 10, H for base 16 sigDigitCount : digitB32 digitB32 ; // digit count of significand, value between 1 and 999 expDigitCount : digitB32 ; // digit count of exponent, value between 0 and 15 sigSign : "+" | "-" ; // sign of significand sigDigits : digitB10+ | digitB16+ ; // digits of significand expSign : "+" | "-" ; // sign of exponent expDigits : digitB10+ | digitB16+ ; // digits of exponent digitB10 : "0" .. "9" ; // representing values between 0 and 9 digitB16 : "0" .. "?" ; // representing values between 0 and 15 digitB32 : "0" .. "O" ; // representing values between 0 and 31 terminator : ASCII(0) ; Conversion PrimitivesThe following conversion primitives should be implemented by all library defined scalar types to facilitate conversion between all numeric types even if no direct conversion path exists: PROCEDURE [TO] toSerialized ( value : <ScalarType>; VAR serialized : ARRAY OF CHAR ); (* Converts <value> to its serialised scalar representation and passes the result back in <serialized>. The output is shortened if the size of the passed in character array is insufficient to represent all available digits. *) PROCEDURE [FROM] fromSerialized ( VAR value : <ScalarType>; serialized : ARRAY OF CHAR ); (* Converts the passed in serialised scalar to a value of type <ScalarType> and passes the result back in <value>. *) |