XDR
1 XDR Data Types
2 License
8.18

XDR🔗ℹ

Rob Durst <me@robdurst.com>

 (require xdr) package: XDR

This package provides a Racket implementation of the XDR (External Data Representation) protocol.

The process for leveraging XDR (RFC 4506) is as follows:

  1. Define XDR configuration files. As an example, the Stellar Blockchain network uses XDR to define the structure of its messages. An XDR enum might look like:
    0 enum {
    1   RED = 2,
    2   YELLOW = 3,
    3   BLUE = 5
    4 } colors;

  2. Use the xdr-parse function to parse the XDR configuration files and generate Racket code.

    (xdr-parse "path/to/xdr/file")

  3. Use the generated Racket code to encode and decode XDR data.
    (xdr-enum-colors RED)
    (xdr-enum-colors 2)

1 XDR Data Types🔗ℹ

This implementation provides the following XDR data types as defined in RFC 4506:

  • xdr-int: 32-bit signed integers in two’s complement notation, range [-2147483648, 2147483647]

  • xdr-uint: 32-bit unsigned integers, range [0, 4294967295]

  • xdr-hyper: 64-bit signed integers in two’s complement notation

  • xdr-uhyper: 64-bit unsigned integers, range [0, 18446744073709551615]

  • xdr-boolean: Boolean values encoded as 32-bit integers (0 for FALSE, 1 for TRUE)

  • xdr-string: Variable-length ASCII strings with length prefix and padding

  • xdr-opaque: Variable-length opaque data with length prefix and padding

  • xdr-fixed-opaque: Fixed-length opaque data with padding to 4-byte boundaries

Each type includes encoding and decoding functions following the pattern xdr-encode-TYPE and xdr-decode-TYPE.

2 License🔗ℹ

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.