Port NBT impl from LibAC Dart
This commit is contained in:
parent
0a022634c1
commit
ad7b619706
55 changed files with 3226 additions and 2983 deletions
82
NBT/ByteArrayTag.cs
Normal file
82
NBT/ByteArrayTag.cs
Normal file
|
@ -0,0 +1,82 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LibAC.NBT.API;
|
||||
|
||||
namespace LibAC.NBT
|
||||
{
|
||||
public class ByteArrayTag : Tag
|
||||
{
|
||||
public List<byte> Value { get; private set; } = new List<byte>();
|
||||
|
||||
public ByteArrayTag() { }
|
||||
|
||||
private ByteArrayTag(List<byte> value)
|
||||
{
|
||||
Value.AddRange(value);
|
||||
}
|
||||
|
||||
public static ByteArrayTag ValueOf(List<byte> value)
|
||||
{
|
||||
return new ByteArrayTag(value);
|
||||
}
|
||||
|
||||
public override void ReadValue(ByteLayer data)
|
||||
{
|
||||
int len = data.ReadInt();
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
Value.Add(data.ReadByte());
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteValue(ByteLayer data)
|
||||
{
|
||||
data.WriteInt(Value.Count);
|
||||
foreach (byte i in Value)
|
||||
{
|
||||
data.WriteByte(i);
|
||||
}
|
||||
}
|
||||
|
||||
public override TagType GetTagType()
|
||||
{
|
||||
return TagType.ByteArray;
|
||||
}
|
||||
|
||||
public override dynamic GetValue()
|
||||
{
|
||||
return null; // Implementation-specific value retrieval
|
||||
}
|
||||
|
||||
public override void SetValue(dynamic val)
|
||||
{
|
||||
// Implementation-specific value setting
|
||||
}
|
||||
|
||||
public override void PrettyPrint(int indent, bool recurse)
|
||||
{
|
||||
string array = string.Join(", ", Value);
|
||||
Console.WriteLine($"{new string('\t', indent)}{Tag.GetCanonicalName(GetTagType())}: [{array}]");
|
||||
}
|
||||
|
||||
public override void WriteStringifiedValue(StringBuilder builder, int indent, bool isList)
|
||||
{
|
||||
builder.Append($"{(isList ? new string('\t', indent) : "")}[B; {string.Join("B, ", Value)}B]");
|
||||
}
|
||||
|
||||
public override void ReadStringifiedValue(StringReader reader)
|
||||
{
|
||||
reader.Expect('[');
|
||||
reader.Expect('B');
|
||||
reader.Expect(';');
|
||||
while (reader.Peek() != ']')
|
||||
{
|
||||
Value.Add(byte.Parse(reader.ReadNumber()));
|
||||
reader.Expect('b');
|
||||
|
||||
if (reader.Peek() == ',') reader.Next();
|
||||
}
|
||||
reader.Expect(']');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue