private IStackItem DeserializeStackItem(IExecutionEngine engine, BinaryReader reader)
        {
            EStackItemType type = (EStackItemType)reader.ReadByte();

            switch (type)
            {
            case EStackItemType.ByteArray:
                return(engine.CreateByteArray(reader.ReadVarBytes()));

            case EStackItemType.Bool:
                return(engine.CreateBool(reader.ReadBoolean()));

            case EStackItemType.Integer:
                return(engine.CreateInteger(new BigInteger(reader.ReadVarBytes())));

            case EStackItemType.Array:
            case EStackItemType.Struct:
            {
                IArrayStackItem array;

                if (type == EStackItemType.Struct)
                {
                    array = engine.CreateStruct();
                }
                else
                {
                    array = engine.CreateArray();
                }

                ulong count = reader.ReadVarInt();
                while (count-- > 0)
                {
                    array.Add(DeserializeStackItem(engine, reader));
                }

                return(array);
            }

            case EStackItemType.Map:
            {
                IMapStackItem map = engine.CreateMap();

                ulong count = reader.ReadVarInt();
                while (count-- > 0)
                {
                    IStackItem key   = DeserializeStackItem(engine, reader);
                    IStackItem value = DeserializeStackItem(engine, reader);

                    map[key] = value;

                    key.Dispose();
                    value.Dispose();
                }

                return(map);
            }

            default: throw new FormatException();
            }
        }