OSTree: Use dictionary types where appropriate.

Change-Id: I58be4cbcdd663350d7524ec5ce97f1d3be10d7e1
diff --git a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/Metadata.java b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/Metadata.java
index cf838d3..8bb5255 100644
--- a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/Metadata.java
+++ b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/Metadata.java
@@ -3,29 +3,18 @@
 import eu.mulk.jgvariant.core.Decoder;
 import eu.mulk.jgvariant.core.Variant;
 import java.nio.charset.StandardCharsets;
-import java.util.List;
+import java.util.Map;
 
 /**
  * A wrapper for a list of metadata fields.
  *
  * <p>Reference: (embedded in other data types)
  */
-public record Metadata(List<Field> fields) {
-
-  /** A metadata field with a key and a value. */
-  public record Field(String key, Variant value) {
-
-    private static final Decoder<Field> DECODER =
-        Decoder.ofStructure(
-            Field.class, Decoder.ofString(StandardCharsets.UTF_8), Decoder.ofVariant());
-
-    public static Decoder<Field> decoder() {
-      return DECODER;
-    }
-  }
+public record Metadata(Map<String, Variant> fields) {
 
   private static final Decoder<Metadata> DECODER =
-      Decoder.ofArray(Field.decoder()).map(Metadata::new);
+      Decoder.ofDictionary(Decoder.ofString(StandardCharsets.UTF_8), Decoder.ofVariant())
+          .map(Metadata::new);
 
   public static Decoder<Metadata> decoder() {
     return DECODER;
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 2fc5c25..303e344 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
@@ -4,7 +4,7 @@
 import eu.mulk.jgvariant.core.Variant;
 import java.nio.ByteOrder;
 import java.nio.charset.StandardCharsets;
-import java.util.List;
+import java.util.Map;
 
 /**
  * A {@link DeltaSuperblock} signed with some sort of key.
@@ -12,25 +12,14 @@
  * <p>Reference: {@code ostree-repo-static-delta-private.h#OSTREE_STATIC_DELTA_SIGNED_FORMAT}
  */
 public record SignedDelta(
-    long magicNumber, ByteString superblock, List<SignedDelta.Signature> signatures) {
-
-  /** A cryptographic signature. */
-  public record Signature(String key, Variant data) {
-    private static final Decoder<Signature> DECODER =
-        Decoder.ofStructure(
-            Signature.class, Decoder.ofString(StandardCharsets.US_ASCII), Decoder.ofVariant());
-
-    public static Decoder<Signature> decoder() {
-      return DECODER;
-    }
-  }
+    long magicNumber, ByteString superblock, Map<String, Variant> signatures) {
 
   private static final Decoder<SignedDelta> DECODER =
       Decoder.ofStructure(
           SignedDelta.class,
           Decoder.ofLong().withByteOrder(ByteOrder.BIG_ENDIAN),
           ByteString.decoder(),
-          Decoder.ofArray(Signature.decoder()));
+          Decoder.ofDictionary(Decoder.ofString(StandardCharsets.US_ASCII), Decoder.ofVariant()));
 
   public static Decoder<SignedDelta> decoder() {
     return DECODER;
diff --git a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SummarySignature.java b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SummarySignature.java
index a05b96d..13bb432 100644
--- a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SummarySignature.java
+++ b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/SummarySignature.java
@@ -3,7 +3,7 @@
 import eu.mulk.jgvariant.core.Decoder;
 import eu.mulk.jgvariant.core.Variant;
 import java.nio.charset.StandardCharsets;
-import java.util.List;
+import java.util.Map;
 
 /**
  * A collection of cryptographic signatures for a {@link Summary}.
@@ -12,22 +12,11 @@
  *
  * <p>Reference: {@code ostree-repo-static-delta-private.h#OSTREE_SUMMARY_SIG_GVARIANT_STRING}
  */
-public record SummarySignature(List<Signature> signatures) {
-
-  /** A cryptographic signature. */
-  public record Signature(String key, Variant data) {
-
-    private static final Decoder<Signature> DECODER =
-        Decoder.ofStructure(
-            Signature.class, Decoder.ofString(StandardCharsets.UTF_8), Decoder.ofVariant());
-
-    public static Decoder<Signature> decoder() {
-      return DECODER;
-    }
-  }
+public record SummarySignature(Map<String, Variant> signatures) {
 
   private static final Decoder<SummarySignature> DECODER =
-      Decoder.ofArray(Signature.decoder()).map(SummarySignature::new);
+      Decoder.ofDictionary(Decoder.ofString(StandardCharsets.UTF_8), Decoder.ofVariant())
+          .map(SummarySignature::new);
 
   public static Decoder<SummarySignature> decoder() {
     return DECODER;
diff --git a/jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderTest.java b/jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderTest.java
index 5e4d37c..05da7ed 100644
--- a/jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderTest.java
+++ b/jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderTest.java
@@ -10,6 +10,7 @@
 import eu.mulk.jgvariant.core.Variant;
 import java.nio.ByteBuffer;
 import java.util.List;
+import java.util.Map;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
@@ -57,10 +58,9 @@
                             Checksum.ofHex(
                                 "66ff167ff35ce87daac817447a9490a262ee75f095f017716a6eb1a9d9eb3350"),
                             new Metadata(
-                                List.of(
-                                    new Metadata.Field(
-                                        "ostree.commit.timestamp",
-                                        new Variant(Signature.parse("t"), 1640537170L))))))),
+                                Map.of(
+                                    "ostree.commit.timestamp",
+                                    new Variant(Signature.parse("t"), 1640537170L)))))),
                 summary.entries()));
     // FIXME: check metadata field
     System.out.println(summary);