Add a network packet system
This commit is contained in:
parent
71f028f25c
commit
a082210fa9
4 changed files with 266 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:libac_flutter/nbt/Stream.dart';
|
||||
import 'package:libac_flutter/nbt/Tag.dart';
|
||||
import 'package:libac_flutter/nbt/impl/CompoundTag.dart';
|
||||
|
@ -68,4 +70,22 @@ class NbtIo {
|
|||
_io.resetPosition();
|
||||
return Tag.readNamedTag(_io) as CompoundTag;
|
||||
}
|
||||
|
||||
static Future<Uint8List> writeToStream(CompoundTag tag) async {
|
||||
_io = ByteLayer();
|
||||
Tag.writeNamedTag(tag, _io);
|
||||
_io.compress();
|
||||
|
||||
return _io.bytes;
|
||||
}
|
||||
|
||||
static Future<CompoundTag> readFromStream(Uint8List list) async {
|
||||
_io = ByteLayer();
|
||||
_io.writeBytes(list);
|
||||
_io.resetPosition();
|
||||
_io.decompress();
|
||||
_io.resetPosition();
|
||||
|
||||
return Tag.readNamedTag(_io) as CompoundTag;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue