"Sputnik" help  
Sputnik Help
BinaryLen(<binary>,[<newSize>],[<filler>])

Description

The BinaryLen function is used to retrieve the length of a binary string or set a new size for a binary string. When called with only the binary parameter, it returns the length of the binary string. If the newSize parameter is provided, the function sets the new size for the binary string and returns the updated length. Additionally, the filler parameter can be used to specify a byte value to fill the new bytes when resizing the binary string.

Parameters

<binary> The binary string for which the length is to be retrieved or resized.
<newSize> Optional new size to set for the binary string. If provided, the function will resize the binary string to the specified size.
<filler> Optional byte value used to fill the new bytes when resizing the binary string. It defaults to 0x00 if not provided.

Return Value

Success: Returns size of binary if only 1 param used otherwise returns new size of the binary after the resize.
Failure: Returns -1 if cannot obtain the size.

Remarks

If the newSize parameter is less than the current length of the binary string, the function will truncate the binary string to the new size.
If the newSize parameter is greater than the current length of the binary string, the function will append new bytes to the binary string to reach the new size. The filler parameter determines the byte value used for the new bytes.
If the resizing operation fails due to memory constraints or other errors, the function returns -1.
If any of the input parameters are null or empty, the function returns -1.

Related

Count

Example

Example of usage:

my $binary = (binary)"Hello World";
my $length = BinaryLen($binary);
say $length;

my $newSize = 15;
my $resizedLength = BinaryLen($binary, $newSize, 0xFF);
say $resizedLength;

// PRINTS
// 11
// 15

 


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org