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;
21 using System.Diagnostics.Contracts;
26 public class ByteQueueException : Exception
28 public ByteQueueException()
32 public ByteQueueException(string message)
37 public ByteQueueException(string message, Exception inner)
38 : base(message, inner)
43 public class ByteQueue
46 private List<byte> _Elements;
48 public ByteQueue(byte[] List, int Start)
50 _Elements = new List<byte>(List);
54 public ByteQueue(byte[] List)
56 _Elements = new List<byte>(List);
60 public ByteQueue(List<byte> List, int Start)
62 _Elements = new List<byte>(List);
66 public ByteQueue(List<byte> List)
68 _Elements = new List<byte>(List);
74 if (_Elements.Count <= _Index)
76 throw new ByteQueueException("No elements left.");
79 return _Elements[_Index++];
82 public byte GetCurrent()
84 return _Elements[_Index];
87 public byte[] Get(int nCount)
89 Contract.Requires<ArgumentException>(Count - Index >= nCount, "nCount is greater than amount of elements.");
91 var result = _Elements.GetRange(_Index, nCount).ToArray();
97 public byte[] GetCurrent(int nCount)
99 Contract.Requires<ArgumentException>(Count - Index >= nCount, "nCount is greater than amount of elements.");
101 var result = _Elements.GetRange(_Index, nCount).ToArray();
107 /// Current index value
111 get { return _Index; }
116 get { return _Elements.Count; }
119 public ulong GetVarInt()
126 return BitConverter.ToUInt16(Get(2), 0);
128 return BitConverter.ToUInt32(Get(4), 0);
130 return BitConverter.ToUInt64(Get(8), 0);