Array

extension Array: XDRCodable where Element: XDRCodable

Extension making Array conform to XDRCodable when elements are XDRCodable.

Arrays in XDR are encoded with a 32-bit count prefix followed by the elements.

Available where Element: XDRCodable

  • Encodes the array to XDR format.

    Writes the element count as UInt32 followed by each element.

    Declaration

    Swift

    public func xdrEncode(to encoder: XDREncoder) throws
  • Decodes a variable-length array from XDR format.

    Reads the element count as UInt32 followed by the elements. This is also the byte reader behind String and Data, whose elements are single UInt8 values; every other element type occupies at least 4 bytes. The count is validated against the remaining bytes at that minimum width before storage is reserved for it.

    Throws

    StellarSDKError.xdrDecodingError if the count exceeds what the remaining bytes can hold, XDRDecoder.Error if decoding an element fails

    Declaration

    Swift

    public init(fromBinary decoder: XDRDecoder) throws
  • Decodes a fixed-length array from XDR format.

    Reads exactly count elements with no count prefix, the layout of an XDR fixed-length array. The count is validated against the remaining bytes at the minimum element width (1 byte for UInt8, 4 bytes otherwise) before storage is reserved for it.

    Throws

    StellarSDKError.xdrDecodingError if the count is negative or exceeds what the remaining bytes can hold, XDRDecoder.Error if decoding an element fails

    Declaration

    Swift

    public init(fromBinary decoder: XDRDecoder, count: Int) throws

    Parameters

    decoder

    Decoder to read from

    count

    Number of elements to read