33 lines
967 B
C#
33 lines
967 B
C#
using Godot;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Network.PacketHandling {
|
|
public class PacketBuffer {
|
|
|
|
private List<byte> ByteList = new List<byte>();
|
|
private int ReadCounter = 0;
|
|
|
|
public byte[] ByteBuffer { get { return ByteList.ToArray(); } }
|
|
public int Length { get { return ByteList.Count; } }
|
|
public bool HasNext { get { return ReadCounter < ByteList.Count; } }
|
|
|
|
public byte Read() {
|
|
if (!HasNext) {
|
|
GD.printerr("Attempted to read byte; Impossible, byte buffer ended.");
|
|
return 0;
|
|
}
|
|
return ByteList[ReadCounter++];
|
|
}
|
|
|
|
public void Write(byte toWrite) {
|
|
ByteList.Add(toWrite);
|
|
}
|
|
|
|
public static PacketBuffer FromByteBuffer(byte[] byteBuffer) {
|
|
PacketBuffer PB = new PacketBuffer();
|
|
PB.ByteList = new List<byte>(byteBuffer);
|
|
return PB;
|
|
}
|
|
|
|
}
|
|
} |