Skip to content

Commit

Permalink
consistent enum construction.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpe7s committed Aug 16, 2024
1 parent fb55416 commit 713cf22
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ext {

sava = '1.2.3'
sava_solana_programs = '1.1.0'
sava_anchor_src_gen = '1.1.4'
sava_anchor_src_gen = '1.1.7'
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static MarginCalculationMode read(final byte[] _data, final int offset) {
final int ordinal = _data[offset] & 0xFF;
final int i = offset + 1;
return switch (ordinal) {
case 0 -> new Standard(_data[i] == 1);
case 0 -> Standard.read(_data, i);
case 1 -> Liquidation.read(_data, i);
default -> throw new IllegalStateException(java.lang.String.format(
"Unexpected ordinal [%d] for enum [MarginCalculationMode]", ordinal
Expand All @@ -20,8 +20,11 @@ static MarginCalculationMode read(final byte[] _data, final int offset) {

record Standard(boolean val) implements EnumBool, MarginCalculationMode {

public static final Standard TRUE = new Standard(true);
public static final Standard FALSE = new Standard(false);

public static Standard read(final byte[] _data, int i) {
return new Standard(_data[i] == 1);
return _data[i] == 1 ? Standard.TRUE : Standard.FALSE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ static ModifyOrderId read(final byte[] _data, final int offset) {
final int ordinal = _data[offset] & 0xFF;
final int i = offset + 1;
return switch (ordinal) {
case 0 -> new UserOrderId(_data[i] & 0xFF);
case 1 -> new OrderId(getInt32LE(_data, i));
case 0 -> UserOrderId.read(_data, i);
case 1 -> OrderId.read(_data, i);
default -> throw new IllegalStateException(java.lang.String.format(
"Unexpected ordinal [%d] for enum [ModifyOrderId]", ordinal
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ static EngineFieldValue read(final byte[] _data, final int offset) {
final int ordinal = _data[offset] & 0xFF;
final int i = offset + 1;
return switch (ordinal) {
case 0 -> new Boolean(_data[i] == 1);
case 0 -> Boolean.read(_data, i);
case 1 -> Date.read(_data, i);
case 2 -> new Double(getInt64LE(_data, i));
case 3 -> new Integer(getInt32LE(_data, i));
case 2 -> Double.read(_data, i);
case 3 -> Integer.read(_data, i);
case 4 -> String.read(_data, i);
case 5 -> Time.read(_data, i);
case 6 -> new U8(_data[i] & 0xFF);
case 7 -> new U64(getInt64LE(_data, i));
case 8 -> new Pubkey(readPubKey(_data, i));
case 9 -> new Percentage(getInt32LE(_data, i));
case 6 -> U8.read(_data, i);
case 7 -> U64.read(_data, i);
case 8 -> Pubkey.read(_data, i);
case 9 -> Percentage.read(_data, i);
case 10 -> URI.read(_data, i);
case 11 -> new Timestamp(getInt64LE(_data, i));
case 11 -> Timestamp.read(_data, i);
case 12 -> VecPubkey.read(_data, i);
case 13 -> VecU32.read(_data, i);
case 14 -> VecAcl.read(_data, i);
Expand All @@ -54,8 +54,11 @@ static EngineFieldValue read(final byte[] _data, final int offset) {

record Boolean(boolean val) implements EnumBool, EngineFieldValue {

public static final Boolean TRUE = new Boolean(true);
public static final Boolean FALSE = new Boolean(false);

public static Boolean read(final byte[] _data, int i) {
return new Boolean(_data[i] == 1);
return _data[i] == 1 ? Boolean.TRUE : Boolean.FALSE;
}

@Override
Expand Down

0 comments on commit 713cf22

Please sign in to comment.