内に含ま
その他のドキュメントサポート リソース | PDF 文書ファイルをダウンロードする (1148 KB)
Appendix C XDR Protocol SpecificationThis appendix contains the XDR Protocol Language Specification. It covers the following topics: XDR Protocol IntroductionExternal data representation (XDR) is a standard for the description and encoding of data. The XDR protocol is useful for transferring data between different computer architectures and has been used to communicate data between very diverse machines. XDR fits into the ISO reference model's presentation layer (layer 6) and is roughly analogous in purpose to X.409, ISO Abstract Syntax Notation. The major difference between the two is that XDR uses implicit typing, while X.409 uses explicit typing. XDR uses a language to describe data formats and can only be used to describe data. It is not a programming language. This language enables you to describe intricate data formats in a concise manner. The XDR language is similar to the C language. Protocols such as RPC and NFS use XDR to describe the format of their data. The XDR standard assumes that bytes, or octets, are portable and that a byte is defined to be 8 bits of data. Graphic Box NotationThis appendix uses graphic box notation for illustration and comparison. In most illustrations, each box depicts a byte. The representation of all items requires a multiple of 4 bytes (or 32 bits) of data. The bytes are numbered 0 through n -1. The bytes are read or written to some byte stream such that byte m always precedes byte m+1. The n bytes are followed by enough (0 to 3) residual zero bytes, r, to make the total byte count a multiple of four. Ellipses (...) between boxes show zero or more additional bytes where required, as shown in the following illustration.
Basic Block SizeChoosing the XDR block size requires a tradeoff. Choosing a small size such as 2 makes the encoded data small, but causes alignment problems for machines that are not aligned on these boundaries. A large size such as 8 means the data is aligned on virtually every machine, but causes the encoded data to grow too large. Four was chosen as a compromise. Four is big enough to support most architectures efficiently. This basic block size of 4 does not mean that the computers cannot utilize standard XDR, just that they do so at a greater overhead per data item than 4-byte (32-bit) architectures. Four is also small enough to keep the encoded data restricted to a reasonable size. The same data should encode into an equivalent result on all machines so that encoded data can be compared or checksummed. So, variable-length data must be padded with trailing zeros. XDR Data Type DeclarationsEach of the sections that follow:
For each data type in the language a general paradigm declaration is shown. Note that angle brackets (< and >) denote variable-length sequences of data and square brackets ([and]) denote fixed-length sequences of data. n, m, and r denote integers. For the full language specification, refer to XDR Language Specification. Some data types include specific examples. A more extensive example is given in the section XDR Data Description. Signed IntegerAn XDR signed integer is a 32-bit datum that encodes an integer in the range [-2147483648,2147483647]. The integer is represented in two's complement notation; the most and least significant bytes are 0 and 3, respectively. DeclarationIntegers are declared: int identifier; Signed Integer Encoding
Unsigned IntegerAn XDR unsigned integer is a 32-bit datum that encodes a nonnegative integer in the range [0, 4294967295]. The integer is represented by an unsigned binary number that has most- and least-significant bytes of 0 and 3 respectively. DeclarationAn unsigned integer is declared as follows. unsigned int identifier; Unsigned Integer Encoding
EnumerationsEnumerations have the same representation as signed integers and are handy for describing subsets of the integers. The encoding for enumerations is the same as shown in Signed Integer Encoding. Enumerated data is declared as follows. enum {name-identifier = constant, ... } identifier;
For example, an enumerated type could represent the three colors red, yellow, and blue as follows. enum {RED = 2, YELLOW = 3, BLUE = 5} colors;
Do not assign to an BooleansBooleans are important enough and occur frequently enough to warrant their own explicit type in the standard. Booleans are integers of value 0 or 1. The encoding for Booleans is the same as show in Signed Integer Encoding. Booleans are declared as follows. bool identifier; This is equivalent to: enum {FALSE = 0, TRUE = 1} identifier;
Hyper Integer and Unsigned Hyper IntegerThe standard defines 64–bit (8-byte) numbers called DeclarationHyper integers are declared as follows. hyper int identifier; unsigned hyper int identifier; Hyper Integer Encoding
Floating PointThe standard defines the floating-point data type S: The sign of the number. Values 0 and 1 represent positive and negative respectively. One bit. E: The exponent of the number, base 2. Eight bits are in this field. The exponent is biased by 127. F: The fractional part of the number's mantissa, base 2. Twenty-three bits are in this field. Therefore, the floating-point number is described by. (-1)**S * 2**(E-Bias) * 1.F DeclarationSingle-precision floating-point data is declared as follows. float identifier; Double-precision floating-point data is declared as follows. double identifier; Double-Precision Floating Point Encoding![]() Just as the most and least significant bytes of an integer are 0 and 3, the most-significant and least-significant bits of a double-precision floating-point number are 0 and 63. The beginning bit, and most significant bit, offsets of S, E, and F are 0, 1, and 12 respectively. These offsets refer to the logical positions of the bits, not to their physical locations, which vary from medium to medium. Consult the IEEE specifications about the encoding for signed zero, signed infinity (overflow), and de-normalized numbers (underflow) [1]. According to IEEE specifications, the NaN (not a number) is system dependent and should not be used externally. Quadruple-Precision Floating PointThe standard defines the encoding for the quadruple-precision
floating-point data type S: The sign of the number. Values 0 and 1 represent positive and negative respectively. One bit. E: The exponent of the number, base 2. Fifteen bits are in this field. The exponent is biased by 16383. F: The fractional part of the number's mantissa, base 2. One hundred eleven bits are in this field. Therefore, the floating-point number is described by: (-1)**S * 2**(E-Bias) * 1.F Declarationquadruple identifier; Quadruple-Precision Floating Point Encoding![]() Just as the most-significant and least-significant bytes of an integer are 0 and 3, the most-significant and least-significant bits of a quadruple-precision floating- point number are 0 and 127. The beginning bit, and most-significant bit, offsets of S, E, and F are 0, 1, and 16 respectively. These offsets refer to the logical positions of the bits, not to their physical locations, which vary from medium to medium. Consult the IEEE specifications about the encoding for signed zero, signed infinity (overflow), and de-normalized numbers (underflow) [1]. According to IEEE specifications, the NaN (not a number) is system dependent and should not be used externally. Fixed-Length Opaque DataAt times, fixed-length uninterpreted
data needs to be passed among machines. This data is called DeclarationOpaque data is declared as follows. opaque identifier[n]; In this declaration, the constant n is the static number of bytes necessary to contain the opaque data. The n bytes are followed by enough (0 to 3) residual zero bytes r to make the total byte count of the opaque object a multiple of four. Fixed-Length Opaque EncodingThe n bytes are followed by enough (0 to 3) residual zero bytes r to make the total byte count of the opaque object a multiple of four.
Variable-Length Opaque DataThe standard also provides for variable-length counted opaque data. Such data is defined as a sequence of n (numbered 0 through n-1) arbitrary bytes to be the number n encoded as an unsigned integer, as described subsequently, and followed by the n bytes of the sequence. Byte b of the sequence always precedes byte b+1 of the sequence, and byte 0 of the sequence always follows the sequence's length. The n bytes are followed by enough (0 to 3) residual zero bytes, r, to make the total byte count a multiple of four. DeclarationVariable-length opaque data is declared in the following way. opaque identifier<m>; or opaque identifier<>;; The constant m denotes an upper bound of the number of bytes that the sequence can contain. If m is not specified, as in the second declaration, it is assumed to be (2**32) - 1, the maximum length. For example, a filing protocol might state that the maximum data transfer size is 8192 bytes, as follows. opaque filedata<8192>; Variable-Length Opaque Encoding![]() Do not encode a length greater than the maximum described in the specification. Counted Byte StringsThe standard defines a string of n (numbered 0 through n-1) ASCII bytes to be the number n encoded as an unsigned integer, as described previously, and followed by the n bytes of the string. Byte b of the string always precedes byte b+1 of the string, and byte 0 of the string always follows the string's length. The n bytes are followed by enough (0 to 3) residual zero bytes r to make the total byte count a multiple of four. DeclarationCounted byte strings are declared as follows. string object<m>; or string object<>; The constant m denotes an upper bound of the number of bytes that a string can contain. If m is not specified, as in the second declaration, it is assumed to be (2**32) - 1, the maximum length. The constant m would normally be found in a protocol specification. For example, a filing protocol might state that a file name can be no longer than 255 bytes, as follows. string filename<255>; String Encoding![]() Do not encode a length greater than the maximum described in the specification. Fixed-Length ArrayFixed-length arrays of elements numbered 0 through n-1 are encoded by individually encoding the elements of the array
in their natural order, 0 through n-1.
Each element's size is a multiple of 4 bytes. Though all elements are of the
same type, the elements might have different sizes. For example, in a fixed-length
array of strings, all elements are of type DeclarationDeclarations for fixed-length arrays of homogenous elements are in the following form. type-name identifier[n]; Fixed-Length Array Encoding
Variable-Length ArrayCounted arrays enable variable-length arrays to be encoded as homogeneous elements. The element count n, an unsigned integer, is followed by each array element, starting with element 0 and progressing through element n-1. DeclarationThe declaration for variable-length arrays follows this form. type-name identifier<m>; or type-name identifier<>; The constant m specifies the maximum acceptable element count of an array. If m is not specified, it is assumed to be (2**32) - 1. Counted Array Encoding![]() Do not encode a length greater than the maximum described in the specification. StructureThe components of the structure are encoded in the order of their declaration in the structure. Each component's size is a multiple of 4 bytes, though the components might be different sizes. DeclarationStructures are declared as follows. struct {
component-declaration-A;
component-declaration-B;
...
} identifier;
Structure Encoding
Discriminated UnionA discriminated union is
a type composed of a discriminant followed by a type selected from a set of
prearranged types according to the value of the discriminant. The type of
discriminant is either DeclarationDiscriminated unions are declared as follows. union switch (discriminant-declaration) {
case discriminant-value-A:
arm-declaration-A;
case discriminant-value-B:
arm-declaration-B;
...
default:
default-declaration;
} identifier;
Each case keyword is followed by a legal value of the discriminant. The default arm is optional. If the arm is not specified, then a valid encoding of the union cannot take on unspecified discriminant values. The size of the implied arm is always a multiple of 4 bytes. The discriminated union is encoded as its discriminant followed by the encoding of the implied arm. Discriminated Union Encoding
VoidAn XDR DeclarationThe declaration is simply as follows. void; Constant
The following example defines a symbolic constant DOZEN, equal to 12. const DOZEN = 12; DeclarationThe declaration of a constant follows this form. const name-identifier = n; Typedef
typedef declaration; The new type name is actually the variable name in the declaration part
of the typedef egg eggbox[DOZEN]; Variables declared using the new type name have the same type as the
new type name would have in the eggbox fresheggs; egg fresheggs[DOZEN]; When a typedef <<struct, union, or enum definition>> identifier; can be converted to the alternative form by removing the typedef enum {/* using typedef */
FALSE = 0,
TRUE = 1
} bool;
enum bool {/* preferred alternative */
FALSE = 0,
TRUE = 1
};
This syntax is preferred because you do not have to go to the end of a declaration to learn the name of the new type. Optional-DataThe optional-data union occurs so frequently that it is given a special syntax of its own for declaring it. It is declared as follows. type-name *identifier; This syntax is equivalent to the following union: union switch (bool opted) {
case TRUE:
type-name element;
case FALSE:
void;
} identifier;
The optional-data syntax is also equivalent to the following variable-length array declaration, because the Boolean opted can be interpreted as the length of the array. type-name identifier<1>; Optional data is useful for describing recursive data-structures, such as linked lists and trees. XDR Language SpecificationThis section contains the XDR language specification. Notational ConventionsThis specification uses a modified Backus-Naur Form notation for describing the XDR language. Here is a brief description of the notation:
Lexical NotesThe following conventions are used in the specification.
Syntax NotesThe following are keywords and cannot be used as identifiers:
Only unsigned constants can be used
as size specifications for arrays. If an identifier is used, it must have
been declared previously as an unsigned constant in a Constant and type identifiers within the scope of a specification are in the same namespace and must be declared uniquely within this scope. Similarly, variable names must be unique within the scope of The discriminant of a XDR Data DescriptionThe following example is a short XDR data description of a file data structure that might be used to transfer files from one machine to another. Example C–2 XDR File Data Structureconst MAXUSERNAME = 32;/* max length of a user name */
const MAXFILELEN = 65535; /* max length of a file */
const MAXNAMELEN = 255; /* max length of a file name */
/* Types of files: */
enum filekind {
TEXT = 0, /* ascii data */
DATA = 1, /* raw data */
EXEC = 2 /* executable */
};
/* File information, per kind of file: */
union filetype switch (filekind kind) {
case TEXT:
void; /* no extra information */
case DATA:
string creator<MAXNAMELEN>; /* data creator */
case EXEC:
string interpreter<MAXNAMELEN>; /*proginterptr*/
};
/* A complete file: */
struct file {
string filename<MAXNAMELEN>; /* name of file */
filetype type; /* info about file */
string owner<MAXUSERNAME>; /* owner of file */
opaque data<MAXFILELEN>; /* file data */
};
Suppose now that a user named linda wants to store her LISP program sillyprog that contains just the data "quit." Her file would be encoded as listed in the following table. Table C–1 XDR Data Description Example
RPC Language ReferenceThe RPC language is an extension of the XDR language. The sole extension is the addition of the program and version types. For a description of the RPC extensions to the XDR language, see Appendix B, RPC Protocol and Language Specification. |
||||||||||||||||||||||||||||||||||||||||||||||||||||