Add Decoder#encode.
Implements:
- the encoding part of the GVariant specification
- OSTree-specific encoding instructions for static deltas
Untested.
Change-Id: Idbfd6d7e92a9cdff7d8b138d0ecfa36d4f30eee4
diff --git a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SignedDelta.java b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SignedDelta.java
index 827d5e4..1e1e58e 100644
--- a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SignedDelta.java
+++ b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SignedDelta.java
@@ -31,11 +31,18 @@
Decoder.ofStructure(
SignedDelta.class,
Decoder.ofLong().withByteOrder(ByteOrder.BIG_ENDIAN),
- ByteString.decoder().map(SignedDelta::decodeSuperblock),
+ Decoder.ofByteArray().map(SignedDelta::decodeSuperblock, SignedDelta::encodeSuperblock),
Decoder.ofDictionary(Decoder.ofString(US_ASCII), Decoder.ofVariant()));
- private static DeltaSuperblock decodeSuperblock(ByteString byteString) {
- return DeltaSuperblock.decoder().decode(ByteBuffer.wrap(byteString.bytes()));
+ private static DeltaSuperblock decodeSuperblock(byte[] bytes) {
+ return DeltaSuperblock.decoder().decode(ByteBuffer.wrap(bytes));
+ }
+
+ private static byte[] encodeSuperblock(DeltaSuperblock deltaSuperblock) {
+ var byteBuffer = DeltaSuperblock.decoder().encode(deltaSuperblock);
+ byte[] bytes = new byte[byteBuffer.remaining()];
+ byteBuffer.get(bytes);
+ return bytes;
}
/**