blob: bc944364686853f1df2ca60709d905a02a3ec641 [file] [log] [blame]
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +01001package eu.mulk.jgvariant.ostree;
2
3import eu.mulk.jgvariant.core.Decoder;
4import java.nio.ByteOrder;
5import java.nio.charset.StandardCharsets;
6import 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 Benkard05114642021-12-29 21:51:29 +010014 *
15 * @param entries an entry in the summary file.
16 * @param metadata additional keys and values contained in the summary.
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010017 */
18public record Summary(List<Entry> entries, Metadata metadata) {
19
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010020 /**
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 Benkard4e8423d2021-12-19 22:56:09 +010026 public record Entry(String ref, Value value) {
27
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010028 /**
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 Benkard4e8423d2021-12-19 22:56:09 +010037 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 Benkard05114642021-12-29 21:51:29 +010046 /**
47 * Acquires a {@link Decoder} for the enclosing type.
48 *
49 * @return a possibly shared {@link Decoder}.
50 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010051 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 Benkard05114642021-12-29 21:51:29 +010059 /**
60 * Acquires a {@link Decoder} for the enclosing type.
61 *
62 * @return a possibly shared {@link Decoder}.
63 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010064 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 Benkard05114642021-12-29 21:51:29 +010072 /**
73 * Acquires a {@link Decoder} for the enclosing type.
74 *
75 * @return a possibly shared {@link Decoder}.
76 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010077 public static Decoder<Summary> decoder() {
78 return DECODER;
79 }
80}