MinecraftPrimitiveWriter
ref-структура, предназначенная для записи примитивных типов данных в бинарный поток согласно формату Minecraft-протокола. Она реализована на основе Span<byte>
, что обеспечивает высокую производительность за счёт работы напрямую с памятью, исключая лишние копирования.
Исходный код: MinecraftPrimitiveWriter.cs
Основные методы
- void WriteBoolean(bool value)
Writes a single byte representing a boolean value (1 for true, 0 for false).
- void WriteSignedByte(sbyte value)
Writes a single signed byte to the buffer.
- void WriteUnsignedByte(byte value)
Writes a single unsigned byte to the buffer.
- void WriteUnsignedShort(ushort value)
Writes two bytes in BigEndian format representing an unsigned short integer.
- void WriteSignedShort(short value)
Writes two bytes in BigEndian format representing a signed short integer.
- void WriteSignedInt(int value)
Writes four bytes in BigEndian format representing a signed integer.
- void WriteUnsignedInt(uint value)
Writes four bytes in BigEndian format representing an unsigned integer.
- void WriteSignedLong(long value)
Writes eight bytes in BigEndian format representing a signed long integer.
- void WriteUnsignedLong(ulong value)
Writes eight bytes in BigEndian format representing an unsigned long integer.
- void WriteFloat(float value)
Writes four bytes in BigEndian format representing a floating-point number.
- void WriteDouble(double value)
Writes eight bytes in BigEndian format representing a double-precision floating-point number.
- void WriteUUID(Guid value)
Writes 16 bytes representing a UUID/GUID value.
- void WriteBuffer(ReadOnlySpan<byte> value)
Writes a raw byte buffer to the stream.
- void WriteVarInt(int? value)
Writes a nullable integer in VarInt format. Throws ArgumentNullException if the value is null.
- void WriteVarInt(int value)
Writes an integer in VarInt format (1-5 bytes depending on the value magnitude).
- void WriteVarLong(long value)
Writes a long integer in VarLong format (1-10 bytes depending on the value magnitude).
- void WriteString(string value)
Writes a string in UTF-8 format, prefixed with its length as a VarInt.
- void WriteOptionalNbt(NbtTag? value)
Writes an optional NBT tag. Writes a boolean indicating presence, followed by the tag data if present.
- void WriteNbt(NbtTag value)
Writes an NBT tag to the buffer.
- MemoryOwner<byte> GetWrittenMemory()
Returns the written memory buffer and marks the writer as disposed.
- void Dispose()
Disposes of the writer and releases any allocated resources.