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 java.nio.ByteOrder; |
| 5 | import java.nio.charset.StandardCharsets; |
| 6 | import java.util.List; |
| 7 | |
| 8 | /** |
| 9 | * The summary file of an OSTree repository. |
| 10 | * |
| 11 | * <p>Stored as a file named {@code summary} in the OSTree repository root. |
| 12 | * |
| 13 | * <p>Reference: {@code ostree-core.h#OSTREE_SUMMARY_GVARIANT_STRING} |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 14 | * |
| 15 | * @param entries an entry in the summary file. |
| 16 | * @param metadata additional keys and values contained in the summary. |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 17 | */ |
| 18 | public record Summary(List<Entry> entries, Metadata metadata) { |
| 19 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 20 | /** |
| 21 | * An entry in the summary file of an OSTree repository, describing a ref. |
| 22 | * |
| 23 | * @param ref a ref name. |
| 24 | * @param value data describing the ref. |
| 25 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 26 | public record Entry(String ref, Value value) { |
| 27 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 28 | /** |
| 29 | * The value part of an entry in the summary file of an OSTree repository. |
| 30 | * |
| 31 | * <p>Describes the {@link Commit} currently named by the corresponding ref. |
| 32 | * |
| 33 | * @param size the size of the commit. |
| 34 | * @param checksum the checksum of the commit. |
| 35 | * @param metadata additional metadata describing the commit. |
| 36 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 37 | public record Value(long size, Checksum checksum, Metadata metadata) { |
| 38 | |
| 39 | private static final Decoder<Value> DECODER = |
| 40 | Decoder.ofStructure( |
| 41 | Value.class, |
| 42 | Decoder.ofLong().withByteOrder(ByteOrder.LITTLE_ENDIAN), |
| 43 | Checksum.decoder(), |
| 44 | Metadata.decoder()); |
| 45 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 46 | /** |
| 47 | * Acquires a {@link Decoder} for the enclosing type. |
| 48 | * |
| 49 | * @return a possibly shared {@link Decoder}. |
| 50 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 51 | public static Decoder<Value> decoder() { |
| 52 | return DECODER; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | private static final Decoder<Entry> DECODER = |
| 57 | Decoder.ofStructure(Entry.class, Decoder.ofString(StandardCharsets.UTF_8), Value.decoder()); |
| 58 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 59 | /** |
| 60 | * Acquires a {@link Decoder} for the enclosing type. |
| 61 | * |
| 62 | * @return a possibly shared {@link Decoder}. |
| 63 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 64 | public static Decoder<Entry> decoder() { |
| 65 | return DECODER; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | private static final Decoder<Summary> DECODER = |
| 70 | Decoder.ofStructure(Summary.class, Decoder.ofArray(Entry.decoder()), Metadata.decoder()); |
| 71 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 72 | /** |
| 73 | * Acquires a {@link Decoder} for the enclosing type. |
| 74 | * |
| 75 | * @return a possibly shared {@link Decoder}. |
| 76 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 77 | public static Decoder<Summary> decoder() { |
| 78 | return DECODER; |
| 79 | } |
| 80 | } |