82 lines
2.2 KiB
C#
82 lines
2.2 KiB
C#
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(']');
|
|
}
|
|
}
|
|
}
|