Skip to content

Variable Length Opaque

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

An 'opaque' encoding allows you to pass bytes directly into an XDR buffer without having to interpret them. A variable length opaque value will be allocated as many bytes in the buffer as it needs. However, the spec limits this value to 4294967295 bytes in length.

To encode a variable length opaque value:

use StageRightLabs\PhpXdr\XDR;

// Encode
$xdr = XDR::fresh()->write(hex2bin('12345678'), XDR::OPAQUE_VARIABLE);

To decode a variable length opaque value:

use StageRightLabs\PhpXdr\XDR;
$xdr = XDR::fresh()->write(hex2bin('12345678'), XDR::OPAQUE_VARIABLE);

// Decode
$opaque = $xdr->read(XDR::OPAQUE_VARIABLE);
$opaque == hex2bin('12345678'); // true
Clone this wiki locally