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(IList<byte> List, int Start)
48 Elements = new List<byte>(List);
52 public ByteQueue(IList<byte> List)
54 Elements = new List<byte>(List);
60 if (Elements.Count <= Index)
62 throw new ByteQueueException("No elements left.");
65 return Elements[Index++];
68 public byte GetCurrent()
70 return Elements[Index];
73 public byte[] Get(int Count)
75 if (Elements.Count - Index < Count)
77 throw new ByteQueueException("Unable to read requested amount of data.");
80 byte[] result = Elements.GetRange(Index, Count).ToArray();
86 public byte[] GetCurrent(int Count)
88 if (Elements.Count - Index < Count)
90 throw new ByteQueueException("Unable to read requested amount of data.");
93 byte[] result = Elements.GetRange(Index, Count).ToArray();
99 /// Current index value
101 public int CurrentIndex
103 get { return Index; }
106 public ulong GetVarInt()
113 return BitConverter.ToUInt16(Get(2), 0);
115 return BitConverter.ToUInt32(Get(4), 0);
117 return BitConverter.ToUInt64(Get(8), 0);