Implement LongArrayTag

This commit is contained in:
zontreck 2024-05-04 22:52:55 -07:00
parent 4917419bd3
commit b4b2370e34
3 changed files with 45 additions and 22 deletions

View file

@ -11,6 +11,7 @@ import 'package:libac_flutter/nbt/impl/TagShort.dart';
import 'Stream.dart';
import 'impl/ByteTag.dart';
import 'impl/ListTag.dart';
import 'impl/LongArrayTag.dart';
enum TagType {
End(0),
@ -123,6 +124,10 @@ abstract class Tag {
{
return new IntArrayTag();
}
case TagType.LongArray:
{
return new LongArrayTag();
}
case TagType.List:
{

View file

@ -0,0 +1,40 @@
import 'package:libac_flutter/nbt/Stream.dart';
import 'package:libac_flutter/nbt/Tag.dart';
class LongArrayTag extends Tag {
List<int> _value = [];
LongArrayTag();
LongArrayTag._(List<int> lst) {
_value.addAll(lst);
}
static LongArrayTag valueOf(List<int> value) {
return LongArrayTag._(value);
}
@override
void readValue(ByteLayer data) {
int count = data.readInt();
for (int i = 0; i < count; i++) {
_value.add(data.readLong());
}
}
@override
void writeValue(ByteLayer data) {
data.writeInt(size());
for (int i in _value) {
data.writeLong(i);
}
}
int size() {
return _value.length;
}
@override
TagType getTagType() {
return TagType.LongArray;
}
}

View file

@ -1,22 +0,0 @@
import 'package:libac_flutter/nbt/Stream.dart';
import 'package:libac_flutter/nbt/Tag.dart';
class TagLongArray extends Tag {
final List<int> value;
TagLongArray({required this.value});
@override
void readValue(ByteLayer data) {
// TODO: implement readValue
}
@override
void writeValue(ByteLayer data) {
// TODO: implement writeValue
}
@override
TagType getTagType() {
return TagType.LongArray;
}
}