Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StorageItem: optimize binary representation #2379

Merged
merged 2 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/neo/SmartContract/StorageItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public StorageItem Clone()

public void Deserialize(BinaryReader reader)
{
Value = reader.ReadVarBytes();
Value = reader.ReadBytes((int)(reader.BaseStream.Length));
}

public void FromReplica(StorageItem replica)
Expand Down Expand Up @@ -95,7 +95,7 @@ public void FromReplica(StorageItem replica)

public void Serialize(BinaryWriter writer)
{
writer.WriteVarBytes(Value);
writer.Write(Value);
}

public void Set(BigInteger integer)
Expand Down
4 changes: 2 additions & 2 deletions tests/neo.UnitTests/Ledger/UT_StorageItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void Clone()
[TestMethod]
public void Deserialize()
{
byte[] data = new byte[] { 10, 66, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0 };
byte[] data = new byte[] { 66, 32, 32, 32, 32, 32, 32, 32, 32, 32 };
int index = 0;
using (MemoryStream ms = new MemoryStream(data, index, data.Length - index, false))
{
Expand Down Expand Up @@ -96,7 +96,7 @@ public void Serialize()
}
}

byte[] requiredData = new byte[] { 10, 66, 32, 32, 32, 32, 32, 32, 32, 32, 32 };
byte[] requiredData = new byte[] { 66, 32, 32, 32, 32, 32, 32, 32, 32, 32 };

data.Length.Should().Be(requiredData.Length);
for (int i = 0; i < requiredData.Length; i++)
Expand Down