aboutsummaryrefslogtreecommitdiff
path: root/jgvariant-ostree/src/main/java
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2021-12-30 18:52:10 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2021-12-30 18:52:51 +0100
commite74b800445cbe502511905105e769a1ca33b8381 (patch)
tree4cdda0c008156be25dd8590de23d2873874ef266 /jgvariant-ostree/src/main/java
parent44df94e05e51cf32bb34ff65b2002c114043edc6 (diff)
jgvariant-ostree: DeltaPartPayload: Detect and handle compression byte.
Change-Id: I6d5aa4deb7c94bafae1fb5f92c68cdb4809ceca0
Diffstat (limited to 'jgvariant-ostree/src/main/java')
-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();