Skip to content

Commit

Permalink
impl PrimitiveGet->bytes (byte[])
Browse files Browse the repository at this point in the history
  • Loading branch information
alec1o committed May 19, 2024
1 parent b127951 commit fa4bd45
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/src/partials/PrimitiveGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,29 @@ public BigInteger BigInteger()
return SetError<BigInteger>();
}
}

public byte[] Bytes()
{
try
{
if (!IsValidPrefix(Prefix.Bytes)) throw new InvalidDataException();

int valueSize = BitConverter.ToInt32(VaultArray, Position);

Position += sizeof(int);

if (valueSize <= 0 || valueSize > Vault.Count - Position) throw new InvalidDataException();

byte[] value = Vault.GetRange(Position, valueSize).ToArray();

Position += valueSize;

return value;
}
catch
{
return SetError<byte[]>();
}
}
}
}
Expand Down

0 comments on commit fa4bd45

Please sign in to comment.