Variable-Length Array

The XDR standard provides counted byte arrays for encoding variable-length arrays of homogeneous elements.

The array is encoded as the element count n (an unsigned integer) followed by the encoding of each of the array's elements, starting with element 0 and progressing through element n-1.

Variable-length arrays are declared as follows:

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. See the Variable-Length Array figure (Figure 1).

Figure 1. Variable-Length Array
This diagram contains 3 lines of information. The second line of the diagram is the main line, listing the following: n, element 0, element 1, and a series of dots to signify a continuing sequence ending in element n -1. The first line of the diagram contains the numbers 0 through 4, with 0 on the first border of n and 4 on the shared border of n an element 0. The third line assigns values to parts of the main line as follows: n equals 4 bytes, and element 0 through element n-1 equal n elements.
Note: Encoding a length n greater than the maximum described in the protocol specification causes an error.