forked from neo-project/neo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ByteArrayWrapper.cs
41 lines (35 loc) · 911 Bytes
/
ByteArrayWrapper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Neo.VM.Types;
using System;
namespace Neo.SmartContract.Iterators
{
internal class ByteArrayWrapper : IIterator
{
private readonly byte[] array;
private int index = -1;
public ByteArrayWrapper(PrimitiveType value)
{
this.array = value.Span.ToArray();
}
public void Dispose() { }
public PrimitiveType Key()
{
if (index < 0)
throw new InvalidOperationException();
return index;
}
public bool Next()
{
int next = index + 1;
if (next >= array.Length)
return false;
index = next;
return true;
}
public StackItem Value()
{
if (index < 0)
throw new InvalidOperationException();
return new Integer(array[index]);
}
}
}