Skip to content

Commit

Permalink
add public key array/vector enums.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpe7s committed Aug 15, 2024
1 parent 9312f4b commit ffbfe67
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions core/src/main/java/software/sava/core/borsh/RustEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import software.sava.core.encoding.ByteUtil;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.OptionalLong;
Expand Down Expand Up @@ -158,7 +157,7 @@ default int l() {

default int write(final byte[] data, final int offset) {
data[offset] = (byte) ordinal();
return 1 + Borsh.write(val(), data, 1 + offset);
return 1 + Borsh.write(val(), data, 1 + offset);
}
}

Expand Down Expand Up @@ -199,7 +198,7 @@ interface BorshVectorEnum extends RustEnum {
Borsh[] val();

default int l() {
return 1 + Integer.BYTES + Arrays.stream(val()).mapToInt(Borsh::l).sum();
return 1 + Borsh.len(val());
}

default int write(final byte[] data, final int offset) {
Expand All @@ -213,7 +212,21 @@ interface BorshArrayEnum extends RustEnum {
Borsh[] val();

default int l() {
return 1 + Arrays.stream(val()).mapToInt(Borsh::l).sum();
return 1 + Borsh.fixedLen(val());
}

default int write(final byte[] data, final int offset) {
data[offset] = (byte) ordinal();
return 1 + Borsh.fixedWrite(val(), data, 1 + offset);
}
}

interface PublicKeyVectorEnum extends RustEnum {

PublicKey[] val();

default int l() {
return 1 + Borsh.len(val());
}

default int write(final byte[] data, final int offset) {
Expand All @@ -222,6 +235,20 @@ default int write(final byte[] data, final int offset) {
}
}

interface PublicKeyArrayEnum extends RustEnum {

PublicKey[] val();

default int l() {
return 1 + Borsh.fixedLen(val());
}

default int write(final byte[] data, final int offset) {
data[offset] = (byte) ordinal();
return 1 + Borsh.fixedWrite(val(), data, 1 + offset);
}
}

interface OptionalEnumBool extends RustEnum {

Boolean val();
Expand Down

0 comments on commit ffbfe67

Please sign in to comment.