"Sputnik" help  
Sputnik Help
BinaryWriteBytes(<binary>, <position>, <value>, [<size>])

Description

Writes an array of bytes to a binary string at the specified position.

Parameters

<binary> The binary array to which the bytes will be written.
<position> The position in the binary string to start writing to.
<value> The binary string to be written.
<size> Optional number of bytes to write from the <value>. Default is the length of the <value>.

Return Value

Success: Returns true if the bytes were written successfully.
Failure: Returns null if the position is out of bounds or an error occurs during writing.

Remarks

The BinaryWriteBytes function writes an array of bytes to the binary string at the specified position. It starts writing from the given position and continues until the end of the <value> binary string or until the specified <size> is reached. If <size> is not provided, it defaults to the length of the <value> array. The function returns true if the bytes were written successfully.

Related

BinaryReadBytes

Example

Example of usage:

my $a = BinNew(16);

BinaryWriteBytes($a, 0, Tb("CAT."));
BinaryWriteBytes($a, 4, Tb("DOG."));
BinaryWriteBytes($a, 8, Tb("FOX."));

say BinaryExpand($a, false);

if (@IsLittlEendian)
{
    say Bt(BinaryReadBytes($a, 0, 4)[::-1]);
    say Bt(BinaryReadBytes($a, 4, 4)[::-1]);
    say Bt(BinaryReadBytes($a, 8, 4)[::-1]);
}
else
{
    say Bt(BinaryReadBytes($a, 0, 4));
    say Bt(BinaryReadBytes($a, 4, 4));
    say Bt(BinaryReadBytes($a, 8, 4));
}

// PRINTS
// 2E 54 41 43 2E 47 4F 44 2E 58 4F 46 00 00 00 00 .TAC.GOD.XOF....
// CAT.
// DOG.
// FOX.

 


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