trait VarintTrait

Varint encoding and decoding methods inspired by Go encoding/binary package.

Methods

static int
encodeUnsigned(string $buf, int $x)

Varint encode as unsigned integer.

static int
encodeSigned(string $buf, int $x)

Varint encode as signed integer.

static int
decodeUnsigned(string $buf, int $x)

Varint decode an unsigned integer.

static int
decodeSigned(string $buf, int $x)

Varint decode a signed integer.

Details

at line 33
static int encodeUnsigned(string $buf, int $x)

Varint encode as unsigned integer.

Parameters

string $buf bytestring to hold varint encoding of $x.
int $x the unsigned integer to varint encode.

Return Value

int number of bytes written to buf.

at line 51
static int encodeSigned(string $buf, int $x)

Varint encode as signed integer.

Parameters

string $buf bytestring to hold varint encoding of $x.
int $x the signed integer to varint encode.

Return Value

int number of bytes written to buf.

at line 67
static int decodeUnsigned(string $buf, int $x)

Varint decode an unsigned integer.

Parameters

string $buf bytestring holding varint encoding.
int $x integer to receive the decoded value.

Return Value

int number of bytes read from buf.

at line 96
static int decodeSigned(string $buf, int $x)

Varint decode a signed integer.

Parameters

string $buf bytestring holding varint encoding.
int $x integer to receive the decoded value.

Return Value

int number of bytes read from buf.