Skip to content

Helpers

Ryan Durham edited this page Nov 26, 2021 · 8 revisions

Instantiation

To create a new XDR instance with an empty buffer, use the fresh() method:

use StageRightLabs\PhpXdr\XDR;

$xdr = XDR::fresh()

String Representation

An $xdr object is a wrapper that manages a binary string buffer. As values are encoded the binary representation of those values is appended to the end of the buffer. To transmit the binary value you can either send it as is, or use a utility method to reveal the base 16 or base 64 representations of that binary string.

use StageRightLabs\PhpXdr\XDR;

$xdr = XDR::fresh()->write(42, XDR::INT);

// Hex / Base 16
$xdr->toBase16(); // "0000002a"

// Base 64
$xdr->toBase64(); // "AAAAKg=="

// You can also access the underlying buffer directly:
$xdr->buffer(); // a string containing the bytes of the buffer.

Clone this wiki locally