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;
25 public class ByteQueueException : Exception
27 public ByteQueueException()
31 public ByteQueueException(string message)
36 public ByteQueueException(string message, Exception inner)
37 : base(message, inner)
42 public class ByteQueue
45 private List<byte> Elements;
47 public ByteQueue(IList<byte> List, int Start)
49 Elements = new List<byte>(List);
53 public ByteQueue(IList<byte> List)
55 Elements = new List<byte>(List);
61 if (Elements.Count <= Index)
63 throw new ByteQueueException("No elements left.");
66 return Elements[Index++];
69 public byte GetCurrent()
71 return Elements[Index];
74 public byte[] Get(int Count)
76 if (Elements.Count - Index < Count)
78 throw new ByteQueueException("Unable to read requested amount of data.");
81 byte[] result = Elements.Skip(Index).Take(Count).ToArray();
87 public byte[] GetCurrent(int Count)
89 if (Elements.Count - Index < Count)
91 throw new ByteQueueException("Unable to read requested amount of data.");
94 byte[] result = Elements.Skip(Index).Take(Count).ToArray();
100 /// Current index value
102 public int CurrentIndex
104 get { return Index; }
107 public ulong GetVarInt()
114 return BitConverter.ToUInt16(Get(2), 0);
116 return BitConverter.ToUInt32(Get(4), 0);
118 return BitConverter.ToUInt64(Get(8), 0);