Transfer.fromPointer constructor
Implementation
factory Transfer.fromPointer(Pointer<Void> pointer) {
if (pointer.address == 0) {
return Transfer._(null, code: 0, type: ContentType.nullptr);
}
// Читаем Int32 (4 байта) по адресу
final int code = pointer.cast<Int32>().value;
// Читаем Int16 (2 байта) со смещением 4
final int typeValue = Pointer.fromAddress(
pointer.address + 4,
).cast<Int16>().value;
final Pointer<Utf8> contentPtr = Pointer.fromAddress(
pointer.address + _offset,
).cast<Utf8>();
final String content = contentPtr.toDartString();
return Transfer._(
content,
type: switch (typeValue) {
1 => ContentType.error,
2 => ContentType.payload,
3 => ContentType.message,
_ => throw Exception("Unsupported content type"),
},
code: code,
);
}