2 * Novacoin classes library
3 * Copyright (C) 2015 Alex D. (balthazar.ad@gmail.com)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 using System.Collections.Generic;
24 public class ByteQueueException : Exception
26 public ByteQueueException()
30 public ByteQueueException(string message)
35 public ByteQueueException(string message, Exception inner)
36 : base(message, inner)
41 public class ByteQueue
44 private List<byte> Elements;
46 public ByteQueue(byte[] List, int Start)
48 Elements = new List<byte>(List);
52 public ByteQueue(byte[] List)
54 Elements = new List<byte>(List);
58 public ByteQueue(List<byte> List, int Start)
60 Elements = new List<byte>(List);
64 public ByteQueue(List<byte> List)
66 Elements = new List<byte>(List);
72 if (Elements.Count <= Index)
74 throw new ByteQueueException("No elements left.");
77 return Elements[Index++];
80 public byte GetCurrent()
82 return Elements[Index];
85 public byte[] Get(int Count)
87 if (Elements.Count - Index < Count)
89 throw new ByteQueueException("Unable to read requested amount of data.");
92 var result = Elements.GetRange(Index, Count).ToArray();
98 public byte[] GetCurrent(int Count)
100 if (Elements.Count - Index < Count)
102 throw new ByteQueueException("Unable to read requested amount of data.");
105 var result = Elements.GetRange(Index, Count).ToArray();
111 /// Current index value
113 public int CurrentIndex
115 get { return Index; }
118 public ulong GetVarInt()
125 return BitConverter.ToUInt16(Get(2), 0);
127 return BitConverter.ToUInt32(Get(4), 0);
129 return BitConverter.ToUInt64(Get(8), 0);