Enhance school creation and map management features by updating the API to support mod packs and map layouts. Introduce a new map snapshot protocol for efficient data handling during school sessions. Revise documentation to reflect these changes, including updates to the protocol and architecture documents. Improve UI components for mod selection and map editing, ensuring a better user experience. Update tests to validate new functionalities and ensure robustness.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Text;
|
||||
|
||||
namespace HSchool.Protocol;
|
||||
|
||||
@@ -22,6 +23,14 @@ public ref struct PacketReader(ReadOnlySpan<byte> buffer)
|
||||
|
||||
public MessageType ReadMessageType() => (MessageType)ReadByte();
|
||||
|
||||
public ushort ReadUInt16()
|
||||
{
|
||||
EnsureAvailable(sizeof(ushort));
|
||||
var value = BinaryPrimitives.ReadUInt16LittleEndian(_buffer[_position..]);
|
||||
_position += sizeof(ushort);
|
||||
return value;
|
||||
}
|
||||
|
||||
public uint ReadUInt32()
|
||||
{
|
||||
EnsureAvailable(sizeof(uint));
|
||||
@@ -30,6 +39,16 @@ public ref struct PacketReader(ReadOnlySpan<byte> buffer)
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary><c>u16</c> byte length, then UTF-8. Empty string is a zero length.</summary>
|
||||
public string ReadString()
|
||||
{
|
||||
var byteCount = ReadUInt16();
|
||||
EnsureAvailable(byteCount);
|
||||
var value = Encoding.UTF8.GetString(_buffer.Slice(_position, byteCount));
|
||||
_position += byteCount;
|
||||
return value;
|
||||
}
|
||||
|
||||
public int ReadInt32()
|
||||
{
|
||||
EnsureAvailable(sizeof(int));
|
||||
|
||||
Reference in New Issue
Block a user