Skip to content

Commit

Permalink
add missing fixed length byte array borsh methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpe7s committed Sep 10, 2024
1 parent 6205d65 commit e527432
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions core/src/main/java/software/sava/core/borsh/Borsh.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,24 @@ static int lenOptional(final byte[] bytes) {
return bytes == null || bytes.length == 0 ? 1 : (1 + Integer.BYTES + bytes.length);
}

static int fixedLen(final byte[][] array) {
int len = 0;
static int len(final byte[][] array) {
int len = Integer.BYTES;
for (final var a : array) {
len += len(a);
}
return len;
}

static int len(final byte[][] array) {
return Integer.BYTES + fixedLen(array);
static int fixedLen(final byte[] array) {
return array.length;
}

static int fixedLen(final byte[][] array) {
int len = 0;
for (final var a : array) {
len += fixedLen(a);
}
return len;
}

static byte[] read(final byte[] data, final int offset) {
Expand All @@ -90,6 +98,11 @@ static byte[] read(final byte[] data, final int offset) {
return bytes;
}

static byte[] read(final byte[] bytes, final byte[] data, final int offset) {
System.arraycopy(data, offset, data, 0, bytes.length);
return bytes;
}

static int write(final byte[] bytes, final byte[] data, final int offset) {
ByteUtil.putInt32LE(data, offset, bytes.length);
System.arraycopy(bytes, 0, data, offset + Integer.BYTES, bytes.length);
Expand Down

0 comments on commit e527432

Please sign in to comment.