"Sputnik" help  
Sputnik Help
NbtCompoundRead(<binary/ByteBuffer>)

Description

Reads an NBT compound from a binary string or optionally read it from a ByteBuffer class.

Parameters

<binary/ByteBuffer> The binary string or ByteBuffer instance from which to read the NBT compound.

Return Value

Success: Returns the NBT compound read from the binary string or ByteBuffer.
Failure: Returns null if there is an error during the read operation or if the provided input is invalid.

Remarks

The NbtCompoundRead function allows you to read an NBT compound from a binary string or a ByteBuffer instance. It takes the binary string or ByteBuffer as input and performs the necessary operations to parse and create an NBT compound from the provided data.

If a binary string is provided as the input, the function internally creates a ByteBuffer from the binary string and reads the NBT compound from it.

Related

Example

Example of usage:

my $nbt = NbtNew(@NbtCompound);
NbtCompoundSet($nbt, "Cat", "Meow");
NbtCompoundSet($nbt, "Dog", "Woof");

my $data = NbtCompoundWrite($nbt);
say BinaryExpand($data);

my $nbtRead = NbtCompoundRead($data);
say $nbtRead;
foreach(my $k => my $v in $nbtRead)
    say $k . " -> " . $v;

// PRINTS
// 00 | 4E 42 54 21 0A 00 00 00 03 43 61 74 00 00 00 04 NBT!.....Cat....
// 01 | 4D 65 6F 77 0A 00 00 00 03 44 6F 67 00 00 00 04 Meow.....Dog....
// 02 | 57 6F 6F 66 00 -- -- -- -- -- -- -- -- -- -- -- Woof.
// {NBTTag;Compound::[Cat:Meow,Dog:Woof]}
// Cat -> Meow
// Dog -> Woof

Example of using a ByteBuffer class:

my $nbt1 = NbtNew(@NbtCompound);
NbtCompoundSet($nbt1, "Cat1", "Meow1");
NbtCompoundSet($nbt1, "Dog1", "Woof1");

my $nbt2 = NbtNew(@NbtCompound);
NbtCompoundSet($nbt2, "Cat2", "Meow2");
NbtCompoundSet($nbt2, "Dog2", "Woof2");

my $buf = new ByteBuffer();

NbtCompoundWrite($nbt1, $buf);
NbtCompoundWrite($nbt2, $buf);

$buf->Rewind();

my $nbtRead1 = NbtCompoundRead($buf);
my $nbtRead2 = NbtCompoundRead($buf);

say $nbtRead1;
foreach(my $k => my $v in $nbtRead1)
    say $k . " -> " . $v;
say $nbtRead2;
foreach(my $k => my $v in $nbtRead2)
    say $k . " -> " . $v;

// PRINTS
// {NBTTag;Compound::[Cat1:Meow1,Dog1:Woof1]}
// Cat1 -> Meow1
// Dog1 -> Woof1
// {NBTTag;Compound::[Cat2:Meow2,Dog2:Woof2]}
// Cat2 -> Meow2
// Dog2 -> Woof2

 


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