public static int GetByteLength(this StackItem item) { return(item switch { PrimitiveType p => p.Size, Buffer b => b.Size, _ => throw new ArgumentException(), });
public static StackItem Deserialize(BinaryReader reader, uint maxArraySize, uint maxItemSize, ReferenceCounter referenceCounter) { Stack <StackItem> deserialized = new Stack <StackItem>(); int undeserialized = 1; while (undeserialized-- > 0) { StackItemType type = (StackItemType)reader.ReadByte(); switch (type) { case StackItemType.Any: deserialized.Push(StackItem.Null); break; case StackItemType.Boolean: deserialized.Push(reader.ReadBoolean()); break; case StackItemType.Integer: deserialized.Push(new BigInteger(reader.ReadVarBytes(Integer.MaxSize))); break; case StackItemType.ByteString: deserialized.Push(reader.ReadVarBytes((int)maxItemSize)); break; case StackItemType.Buffer: Buffer buffer = new Buffer((int)reader.ReadVarInt(maxItemSize)); reader.FillBuffer(buffer.InnerBuffer); deserialized.Push(buffer); break; case StackItemType.Array: case StackItemType.Struct: { int count = (int)reader.ReadVarInt(maxArraySize); deserialized.Push(new ContainerPlaceholder(type, count)); undeserialized += count; } break; case StackItemType.Map: { int count = (int)reader.ReadVarInt(maxArraySize); deserialized.Push(new ContainerPlaceholder(type, count)); undeserialized += count * 2; } break; default: throw new FormatException(); } } Stack <StackItem> stack_temp = new Stack <StackItem>(); while (deserialized.Count > 0) { StackItem item = deserialized.Pop(); if (item is ContainerPlaceholder placeholder) { switch (placeholder.Type) { case StackItemType.Array: Array array = new Array(referenceCounter); for (int i = 0; i < placeholder.ElementCount; i++) { array.Add(stack_temp.Pop()); } item = array; break; case StackItemType.Struct: Struct @struct = new Struct(referenceCounter); for (int i = 0; i < placeholder.ElementCount; i++) { @struct.Add(stack_temp.Pop()); } item = @struct; break; case StackItemType.Map: Map map = new Map(referenceCounter); for (int i = 0; i < placeholder.ElementCount; i++) { StackItem key = stack_temp.Pop(); StackItem value = stack_temp.Pop(); map[(PrimitiveType)key] = value; } item = map; break; } } stack_temp.Push(item); } return(stack_temp.Peek()); }
public BufferReturn(Neo.VM.Types.Buffer item) { this.value = item.InnerBuffer; this.IsNull = item.IsNull; }