blob: 2b8096d433c33403b463d61f653d7120e1236281 [file] [log] [blame]
Matthias Andreas Benkardb5d657a2022-02-03 21:14:30 +01001// SPDX-FileCopyrightText: © 2021 Matthias Andreas Benkard <code@mail.matthias.benkard.de>
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +01005package eu.mulk.jgvariant.ostree;
6
Matthias Andreas Benkard91dbd742022-10-17 19:38:56 +02007import static java.nio.charset.StandardCharsets.UTF_8;
8
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +01009import eu.mulk.jgvariant.core.Decoder;
10import java.nio.ByteOrder;
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010011import java.util.List;
12
13/**
14 * The summary file of an OSTree repository.
15 *
16 * <p>Stored as a file named {@code summary} in the OSTree repository root.
17 *
18 * <p>Reference: {@code ostree-core.h#OSTREE_SUMMARY_GVARIANT_STRING}
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010019 *
20 * @param entries an entry in the summary file.
21 * @param metadata additional keys and values contained in the summary.
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010022 */
23public record Summary(List<Entry> entries, Metadata metadata) {
24
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010025 /**
26 * An entry in the summary file of an OSTree repository, describing a ref.
27 *
28 * @param ref a ref name.
29 * @param value data describing the ref.
30 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010031 public record Entry(String ref, Value value) {
32
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010033 /**
34 * The value part of an entry in the summary file of an OSTree repository.
35 *
36 * <p>Describes the {@link Commit} currently named by the corresponding ref.
37 *
38 * @param size the size of the commit.
39 * @param checksum the checksum of the commit.
40 * @param metadata additional metadata describing the commit.
41 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010042 public record Value(long size, Checksum checksum, Metadata metadata) {
43
44 private static final Decoder<Value> DECODER =
45 Decoder.ofStructure(
46 Value.class,
47 Decoder.ofLong().withByteOrder(ByteOrder.LITTLE_ENDIAN),
48 Checksum.decoder(),
49 Metadata.decoder());
50
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010051 /**
52 * Acquires a {@link Decoder} for the enclosing type.
53 *
54 * @return a possibly shared {@link Decoder}.
55 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010056 public static Decoder<Value> decoder() {
57 return DECODER;
58 }
59 }
60
61 private static final Decoder<Entry> DECODER =
Matthias Andreas Benkard91dbd742022-10-17 19:38:56 +020062 Decoder.ofStructure(Entry.class, Decoder.ofString(UTF_8), Value.decoder());
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010063
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010064 /**
65 * Acquires a {@link Decoder} for the enclosing type.
66 *
67 * @return a possibly shared {@link Decoder}.
68 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010069 public static Decoder<Entry> decoder() {
70 return DECODER;
71 }
72 }
73
74 private static final Decoder<Summary> DECODER =
75 Decoder.ofStructure(Summary.class, Decoder.ofArray(Entry.decoder()), Metadata.decoder());
76
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010077 /**
78 * Acquires a {@link Decoder} for the enclosing type.
79 *
80 * @return a possibly shared {@link Decoder}.
81 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010082 public static Decoder<Summary> decoder() {
83 return DECODER;
84 }
85}