diff --git a/src/src/primitive/partials/PrimitiveAdd.cs b/src/src/primitive/partials/PrimitiveAdd.cs index 3032a7f..1ae90ea 100644 --- a/src/src/primitive/partials/PrimitiveAdd.cs +++ b/src/src/primitive/partials/PrimitiveAdd.cs @@ -328,13 +328,13 @@ public void BigInteger(BigInteger value) public void Bytes(byte[] value) { - var bytes = value ?? System.Array.Empty(); - Vault.Add(Prefix.Bytes); - uint size = (uint)bytes.LongLength; + var bytes = value ?? System.Array.Empty(); - Vault.AddRange(BitConverter.GetBytes(size)); + var length = (uint)bytes.LongLength; + + Vault.AddRange(BitConverter.GetBytes(length)); if (bytes.Length > 0) Vault.AddRange(bytes); } diff --git a/src/src/primitive/partials/PrimitiveGet.cs b/src/src/primitive/partials/PrimitiveGet.cs index d65cab1..2353bcf 100644 --- a/src/src/primitive/partials/PrimitiveGet.cs +++ b/src/src/primitive/partials/PrimitiveGet.cs @@ -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(); @@ -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(); + + if (valueSize > Vault.Count - Position) throw new InvalidDataException(); var value = Vault.GetRange((int)Position, (int)valueSize).ToArray();