Skip to content

Commit

Permalink
primitive write and read null and empty byte[] (bytes) #29 #30
Browse files Browse the repository at this point in the history
  • Loading branch information
alec1o committed Jul 8, 2024
1 parent 699036d commit 1617732
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/src/primitive/partials/PrimitiveAdd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,13 @@ public void BigInteger(BigInteger value)

public void Bytes(byte[] value)
{
var bytes = value ?? System.Array.Empty<byte>();

Vault.Add(Prefix.Bytes);

uint size = (uint)bytes.LongLength;
var bytes = value ?? System.Array.Empty<byte>();

Vault.AddRange(BitConverter.GetBytes(size));
var length = (uint)bytes.LongLength;

Vault.AddRange(BitConverter.GetBytes(length));

if (bytes.Length > 0) Vault.AddRange(bytes);
}
Expand Down
6 changes: 4 additions & 2 deletions src/src/primitive/partials/PrimitiveGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public string String()
Position += sizeof(uint);

if (valueSize == 0) return default;

if (valueSize > Vault.Count - Position) throw new InvalidDataException();

var value = Vault.GetRange((int)Position, (int)valueSize).ToArray();
Expand Down Expand Up @@ -681,7 +681,9 @@ public byte[] Bytes()

Position += sizeof(uint);

if (valueSize <= 0 || valueSize > Vault.Count - Position) throw new InvalidDataException();
if (valueSize == 0) return System.Array.Empty<byte>();

if (valueSize > Vault.Count - Position) throw new InvalidDataException();

var value = Vault.GetRange((int)Position, (int)valueSize).ToArray();

Expand Down

0 comments on commit 1617732

Please sign in to comment.