add sorting when loading codec values
@@ -3,6 +3,7 @@ package com.quorum.tessera.enclave;
import com.quorum.tessera.version.BaseVersion;
import com.quorum.tessera.version.CBORSupportVersion;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Stream;
public enum EncodedPayloadCodec {
@@ -25,6 +26,11 @@ public enum EncodedPayloadCodec {
public static EncodedPayloadCodec getPreferredCodec(Set<String> versions) {
return Stream.of(EncodedPayloadCodec.values())
+ .sorted((c1, c2) -> {
+ Function<EncodedPayloadCodec, Double> parseValue = c ->
+ Double.parseDouble(c.getMinimumSupportedVersion().replaceAll("[^\\d.]", ""));
+ return Double.compare(parseValue.apply(c2), parseValue.apply(c1));
+ })
.filter(codec -> versions.contains(codec.getMinimumSupportedVersion()))
.findFirst()
.orElse(LEGACY);
