Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame^] | 1 | package eu.mulk.jgvariant.ostree; |
| 2 | |
| 3 | import eu.mulk.jgvariant.core.Decoder; |
| 4 | import eu.mulk.jgvariant.core.Variant; |
| 5 | import java.nio.charset.StandardCharsets; |
| 6 | import java.util.List; |
| 7 | |
| 8 | /** |
| 9 | * A wrapper for a list of metadata fields. |
| 10 | * |
| 11 | * <p>Reference: (embedded in other data types) |
| 12 | */ |
| 13 | public record Metadata(List<Field> fields) { |
| 14 | |
| 15 | /** A metadata field with a key and a value. */ |
| 16 | public record Field(String key, Variant value) { |
| 17 | |
| 18 | private static final Decoder<Field> DECODER = |
| 19 | Decoder.ofStructure( |
| 20 | Field.class, Decoder.ofString(StandardCharsets.UTF_8), Decoder.ofVariant()); |
| 21 | |
| 22 | public static Decoder<Field> decoder() { |
| 23 | return DECODER; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | private static final Decoder<Metadata> DECODER = |
| 28 | Decoder.ofArray(Field.decoder()).map(Metadata::new); |
| 29 | |
| 30 | public static Decoder<Metadata> decoder() { |
| 31 | return DECODER; |
| 32 | } |
| 33 | } |