⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xdr.rfc.ms

📁 RTEMS (Real-Time Executive for Multiprocessor Systems) is a free open source real-time operating sys
💻 MS
📖 第 1 页 / 共 3 页
字号:
The constant m would normally be found in a protocol specification.For example, a filing protocol may state that the maximum datatransfer size is 8192 bytes, as follows:.DS.ft CWopaque filedata<8192>;.DEThis can be illustrated as follows:.ie t .DS.el .DS L\fIVariable-Length Opaque\fP\f(CW0     1     2     3     4     5   ...+-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+|        length n       |byte0|byte1|...| n-1 |  0  |...|  0  |+-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+|<-------4 bytes------->|<------n bytes------>|<---r bytes--->||<----n+r (where (n+r) mod 4 = 0)---->|\fP.DE.LPIt   is  an error  to  encode  a  length  greater  than the maximumdescribed in the specification..NH 2\&String.IX XDR string.LPThe standard defines a string of n (numbered 0 through n-1) ASCIIbytes to be the number n encoded as an unsigned integer (as describedabove), and followed by the n bytes of the string.  Byte m of thestring always precedes byte m+1 of the string, and byte 0 of thestring always follows the string's length.  If n is not a multiple offour, then the n bytes are followed by enough (0 to 3) residual zerobytes, r, to make the total byte count a multiple of four.  Countedbyte strings are declared as follows:.DS.ft CWstring object<m>;.DEor.DS.ft CWstring object<>;.DEThe constant m denotes an upper bound of the number of bytes that astring may contain.  If m is not specified, as in the seconddeclaration, 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 may state that a file name can be nolonger than 255 bytes, as follows:.DS.ft CWstring filename<255>;.DEWhich can be illustrated as:.ie t .DS.el .DS L\fIA String\fP\f(CW0     1     2     3     4     5   ...+-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+|        length n       |byte0|byte1|...| n-1 |  0  |...|  0  |+-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+|<-------4 bytes------->|<------n bytes------>|<---r bytes--->||<----n+r (where (n+r) mod 4 = 0)---->|\fP.DE.LPIt   is an  error  to  encode  a length greater  than   the maximumdescribed in the specification..NH 2\&Fixed-length Array.IX XDR "fixed-length array".IX XDR "array, fixed length".LPDeclarations for fixed-length arrays of homogeneous elements are inthe following form:.DS.ft CWtype-name identifier[n];.DEFixed-length arrays of elements numbered 0 through n-1 are encoded byindividually encoding the elements of the array in their naturalorder, 0 through n-1.  Each element's size is a multiple of fourbytes. Though all elements are of the same type, the elements mayhave different sizes.  For example, in a fixed-length array ofstrings, all elements are of type "string", yet each element willvary in its length..ie t .DS.el .DS L\fIFixed-Length Array\fP\f(CW+---+---+---+---+---+---+---+---+...+---+---+---+---+|   element 0   |   element 1   |...|  element n-1  |+---+---+---+---+---+---+---+---+...+---+---+---+---+|<--------------------n elements------------------->|\fP.DE.NH 2\&Variable-length Array.IX XDR "variable-length array".IX XDR "array, variable length".LPCounted arrays provide the ability to encode variable-length arraysof homogeneous elements.  The array is encoded as the element count n(an unsigned integer) followed by the encoding of each of the array'selements, starting with element 0 and progressing through element n-1.  The declaration for variable-length arrays follows this form:.DS.ft CWtype-name identifier<m>;.DEor.DS.ft CWtype-name identifier<>;.DEThe constant m specifies the maximum acceptable element count of anarray; if  m is not specified, as  in the second declaration, it isassumed to be (2**32) - 1..ie t .DS.el .DS L\fICounted Array\fP\f(CW0  1  2  3+--+--+--+--+--+--+--+--+--+--+--+--+...+--+--+--+--+|     n     | element 0 | element 1 |...|element n-1|+--+--+--+--+--+--+--+--+--+--+--+--+...+--+--+--+--+|<-4 bytes->|<--------------n elements------------->|\fP.DEIt is  an error to  encode  a  value of n that  is greater than themaximum described in the specification..NH 2\&Structure.IX XDR structure.LPStructures are declared as follows:.DS.ft CWstruct {	component-declaration-A;	component-declaration-B;	\&...} identifier;.DEThe components of the structure are encoded in the order of theirdeclaration in the structure.  Each component's size is a multiple offour bytes, though the components may be different sizes..ie t .DS.el .DS L\fIStructure\fP\f(CW+-------------+-------------+...| component A | component B |...+-------------+-------------+...\fP.DE.NH 2\&Discriminated Union.IX XDR "discriminated union".IX XDR union discriminated.LPA discriminated union is a type composed of a discriminant followedby a type selected from a set of prearranged types according to thevalue of the discriminant.  The type of discriminant is either "int","unsigned int", or an enumerated type, such as "bool".  The componenttypes are called "arms" of the union, and are preceded by the valueof the discriminant which implies their encoding.  Discriminatedunions are declared as follows:.DS.ft CWunion switch (discriminant-declaration) {	case discriminant-value-A:	arm-declaration-A;	case discriminant-value-B:	arm-declaration-B;	\&...	default: default-declaration;} identifier;.DEEach "case" keyword is followed by a legal value of the discriminant.The default arm is optional.  If it is not specified, then a validencoding of the union cannot take on unspecified discriminant values.The size of the implied arm is always a multiple of four bytes..LPThe discriminated union is encoded as its discriminant followed bythe encoding of the implied arm..ie t .DS.el .DS L\fIDiscriminated Union\fP\f(CW0   1   2   3+---+---+---+---+---+---+---+---+|  discriminant |  implied arm  |+---+---+---+---+---+---+---+---+|<---4 bytes--->|\fP.DE.NH 2\&Void.IX XDR void.LPAn XDR void is a 0-byte quantity.  Voids are useful for describingoperations that take no data as input or no data as output. They arealso useful in unions, where some arms may contain data and others donot.  The declaration is simply as follows:.DS.ft CWvoid;.DEVoids are illustrated as follows:.ie t .DS.el .DS L\fIVoid\fP\f(CW  ++  ||  ++--><-- 0 bytes\fP.DE.NH 2\&Constant.IX XDR constant.LPThe data declaration for a constant follows this form:.DS.ft CWconst name-identifier = n;.DE"const" is used to define a symbolic name for a constant; it does notdeclare any data.  The symbolic constant may be used anywhere aregular constant may be used.  For example, the following defines asymbolic constant DOZEN, equal to 12..DS.ft CWconst DOZEN = 12;.DE.NH 2\&Typedef.IX XDR typedef.LP"typedef" does not declare any data either, but serves to define newidentifiers for declaring data. The syntax is:.DS.ft CWtypedef declaration;.DEThe new type name is actually the variable name in the declarationpart of the typedef.  For example, the following defines a new typecalled "eggbox" using an existing type called "egg":.DS.ft CWtypedef egg eggbox[DOZEN];.DEVariables declared using the new type name have the same type as thenew type name would have in the typedef, if it was considered avariable.  For example, the following two declarations are equivalentin declaring the variable "fresheggs":.DS.ft CWeggbox  fresheggs;egg     fresheggs[DOZEN];.DEWhen a typedef involves a struct, enum, or union definition, there isanother (preferred) syntax that may be used to define the same type.In general, a typedef of the following form:.DS.ft CWtypedef <<struct, union, or enum definition>> identifier;.DEmay be converted to the alternative form by removing the "typedef"part and placing the identifier after the "struct", "union", or"enum" keyword, instead of at the end.  For example, here are the twoways to define the type "bool":.DS.ft CWtypedef enum {    /* \fIusing typedef\fP */	FALSE = 0,	TRUE = 1	} bool;enum bool {       /* \fIpreferred alternative\fP */	FALSE = 0,	TRUE = 1	};.DEThe reason this syntax is preferred is one does not have to waituntil the end of a declaration to figure out the name of the newtype..NH 2\&Optional-data.IX XDR "optional data".IX XDR "data, optional".LPOptional-data is one kind of union that occurs so frequently that wegive it a special syntax of its own for declaring it.  It is declaredas follows:.DS.ft CWtype-name *identifier;.DEThis is equivalent to the following union:.DS.ft CWunion switch (bool opted) {	case TRUE:	type-name element;	case FALSE:	void;} identifier;.DEIt is also equivalent to the following variable-length arraydeclaration, since the boolean "opted" can be interpreted as thelength of the array:.DS.ft CWtype-name identifier<1>;.DEOptional-data is not so interesting in itself, but it is very usefulfor describing recursive data-structures such as linked-lists andtrees.  For example, the following defines a type "stringlist" thatencodes lists of arbitrary length strings:.DS.ft CWstruct *stringlist {	string item<>;	stringlist next;};.DEIt could have been equivalently declared as the following union:.DS.ft CWunion stringlist switch (bool opted) {	case TRUE:		struct {			string item<>;			stringlist next;		} element;	case FALSE:		void;};.DEor as a variable-length array:.DS.ft CWstruct stringlist<1> {	string item<>;	stringlist next;};.DEBoth of these declarations obscure the intention of the stringlisttype, so the optional-data declaration is preferred over both ofthem.  The optional-data type also has a close correlation to howrecursive data structures are represented in high-level languagessuch as Pascal or C by use of pointers. In fact, the syntax is thesame as that of the C language for pointers..NH 2\&Areas for Future Enhancement

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -