Matthias Andreas Benkard | b5d657a | 2022-02-03 21:14:30 +0100 | [diff] [blame] | 1 | // SPDX-FileCopyrightText: © 2021 Matthias Andreas Benkard <code@mail.matthias.benkard.de> |
| 2 | // |
| 3 | // SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 | |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 5 | package eu.mulk.jgvariant.ostree; |
| 6 | |
Matthias Andreas Benkard | 91dbd74 | 2022-10-17 19:38:56 +0200 | [diff] [blame] | 7 | import static java.nio.charset.StandardCharsets.UTF_8; |
| 8 | |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 9 | import eu.mulk.jgvariant.core.Decoder; |
| 10 | import java.nio.ByteOrder; |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 11 | import 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 Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 19 | * |
| 20 | * @param entries an entry in the summary file. |
| 21 | * @param metadata additional keys and values contained in the summary. |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 22 | */ |
| 23 | public record Summary(List<Entry> entries, Metadata metadata) { |
| 24 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 25 | /** |
| 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 Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 31 | public record Entry(String ref, Value value) { |
| 32 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 33 | /** |
| 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 Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 42 | 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 Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 51 | /** |
| 52 | * Acquires a {@link Decoder} for the enclosing type. |
| 53 | * |
| 54 | * @return a possibly shared {@link Decoder}. |
| 55 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 56 | public static Decoder<Value> decoder() { |
| 57 | return DECODER; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | private static final Decoder<Entry> DECODER = |
Matthias Andreas Benkard | 91dbd74 | 2022-10-17 19:38:56 +0200 | [diff] [blame] | 62 | Decoder.ofStructure(Entry.class, Decoder.ofString(UTF_8), Value.decoder()); |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 63 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 64 | /** |
| 65 | * Acquires a {@link Decoder} for the enclosing type. |
| 66 | * |
| 67 | * @return a possibly shared {@link Decoder}. |
| 68 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 69 | 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 Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 77 | /** |
| 78 | * Acquires a {@link Decoder} for the enclosing type. |
| 79 | * |
| 80 | * @return a possibly shared {@link Decoder}. |
| 81 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 82 | public static Decoder<Summary> decoder() { |
| 83 | return DECODER; |
| 84 | } |
| 85 | } |