2 using System.Collections.Generic;
5 using System.Threading.Tasks;
9 public class ByteQueueException : Exception
11 public ByteQueueException()
15 public ByteQueueException(string message)
20 public ByteQueueException(string message, Exception inner)
21 : base(message, inner)
26 public class ByteQueue
29 private List<byte> Elements;
31 public ByteQueue(IList<byte> List, int Start)
33 Elements = new List<byte>(List);
37 public ByteQueue(IList<byte> List)
39 Elements = new List<byte>(List);
45 if (Elements.Count <= Index)
47 throw new ByteQueueException("No elements left.");
50 return Elements[Index++];
53 public byte GetCurrent()
55 return Elements[Index];
58 public byte[] Get(int Count)
60 if (Elements.Count - Index < Count)
62 throw new ByteQueueException("Unable to read requested amount of data.");
65 byte[] result = Elements.Skip(Index).Take(Count).ToArray();
71 public byte[] GetCurrent(int Count)
73 if (Elements.Count - Index < Count)
75 throw new ByteQueueException("Unable to read requested amount of data.");
78 byte[] result = Elements.Skip(Index).Take(Count).ToArray();
84 /// Current index value
86 public int CurrentIndex
91 public IEnumerable<byte> GetEnumerable(int Count)
93 if (Elements.Count - Index < Count)
95 throw new ByteQueueException("Unable to read requested amount of data.");
98 IEnumerable<byte> result = Elements.Skip(Index).Take(Count);
104 public ulong GetVarInt()
111 return BitConverter.ToUInt16(Get(2), 0);
113 return BitConverter.ToUInt32(Get(4), 0);
115 return BitConverter.ToUInt64(Get(8), 0);