blob: 150ab00f16f77b7243755fdf3ac946e0800fd262 [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
7import eu.mulk.jgvariant.core.Decoder;
8import java.nio.ByteOrder;
9import java.nio.charset.StandardCharsets;
10import java.util.List;
11
12/**
13 * The summary file of an OSTree repository.
14 *
15 * <p>Stored as a file named {@code summary} in the OSTree repository root.
16 *
17 * <p>Reference: {@code ostree-core.h#OSTREE_SUMMARY_GVARIANT_STRING}
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010018 *
19 * @param entries an entry in the summary file.
20 * @param metadata additional keys and values contained in the summary.
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010021 */
22public record Summary(List<Entry> entries, Metadata metadata) {
23
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010024 /**
25 * An entry in the summary file of an OSTree repository, describing a ref.
26 *
27 * @param ref a ref name.
28 * @param value data describing the ref.
29 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010030 public record Entry(String ref, Value value) {
31
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010032 /**
33 * The value part of an entry in the summary file of an OSTree repository.
34 *
35 * <p>Describes the {@link Commit} currently named by the corresponding ref.
36 *
37 * @param size the size of the commit.
38 * @param checksum the checksum of the commit.
39 * @param metadata additional metadata describing the commit.
40 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010041 public record Value(long size, Checksum checksum, Metadata metadata) {
42
43 private static final Decoder<Value> DECODER =
44 Decoder.ofStructure(
45 Value.class,
46 Decoder.ofLong().withByteOrder(ByteOrder.LITTLE_ENDIAN),
47 Checksum.decoder(),
48 Metadata.decoder());
49
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010050 /**
51 * Acquires a {@link Decoder} for the enclosing type.
52 *
53 * @return a possibly shared {@link Decoder}.
54 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010055 public static Decoder<Value> decoder() {
56 return DECODER;
57 }
58 }
59
60 private static final Decoder<Entry> DECODER =
61 Decoder.ofStructure(Entry.class, Decoder.ofString(StandardCharsets.UTF_8), Value.decoder());
62
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010063 /**
64 * Acquires a {@link Decoder} for the enclosing type.
65 *
66 * @return a possibly shared {@link Decoder}.
67 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010068 public static Decoder<Entry> decoder() {
69 return DECODER;
70 }
71 }
72
73 private static final Decoder<Summary> DECODER =
74 Decoder.ofStructure(Summary.class, Decoder.ofArray(Entry.decoder()), Metadata.decoder());
75
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010076 /**
77 * Acquires a {@link Decoder} for the enclosing type.
78 *
79 * @return a possibly shared {@link Decoder}.
80 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010081 public static Decoder<Summary> decoder() {
82 return DECODER;
83 }
84}