aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaPartPayload.java23
1 files changed, 18 insertions, 5 deletions
diff --git a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaPartPayload.java b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaPartPayload.java
index 7f7dd23..99e093d 100644
--- a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaPartPayload.java
+++ b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaPartPayload.java
@@ -1,6 +1,7 @@
package eu.mulk.jgvariant.ostree;
import eu.mulk.jgvariant.core.Decoder;
+import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.List;
@@ -27,11 +28,23 @@ public record DeltaPartPayload(
private static final Decoder<DeltaPartPayload> DECODER =
Decoder.ofStructure(
- DeltaPartPayload.class,
- Decoder.ofArray(FileMode.decoder()),
- Decoder.ofArray(Decoder.ofArray(Xattr.decoder())),
- ByteString.decoder(),
- ByteString.decoder().map(DeltaPartPayload::parseDeltaOperationList));
+ DeltaPartPayload.class,
+ Decoder.ofArray(FileMode.decoder()),
+ Decoder.ofArray(Decoder.ofArray(Xattr.decoder())),
+ ByteString.decoder(),
+ ByteString.decoder().map(DeltaPartPayload::parseDeltaOperationList))
+ .contramap(DeltaPartPayload::preparse);
+
+ private static ByteBuffer preparse(ByteBuffer byteBuffer) {
+ byte compressionByte = byteBuffer.get(0);
+ return switch (compressionByte) {
+ case 0 -> byteBuffer.slice(1, byteBuffer.limit());
+ case (byte) 'x' -> throw new UnsupportedOperationException(
+ "LZMA compression of static deltas is unsupported");
+ default -> throw new IllegalArgumentException(
+ "unrecognized compression byte '%d'".formatted(compressionByte));
+ };
+ }
private static List<DeltaOperation> parseDeltaOperationList(ByteString byteString) {
return byteString.stream().map(DeltaOperation::valueOf).toList();