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 | |
| 7 | import eu.mulk.jgvariant.core.Decoder; |
| 8 | import java.nio.ByteOrder; |
| 9 | import java.nio.charset.StandardCharsets; |
| 10 | import 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 Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 18 | * |
| 19 | * @param entries an entry in the summary file. |
| 20 | * @param metadata additional keys and values contained in the summary. |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 21 | */ |
| 22 | public record Summary(List<Entry> entries, Metadata metadata) { |
| 23 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 24 | /** |
| 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 Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 30 | public record Entry(String ref, Value value) { |
| 31 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 32 | /** |
| 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 Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 41 | 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 Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 50 | /** |
| 51 | * Acquires a {@link Decoder} for the enclosing type. |
| 52 | * |
| 53 | * @return a possibly shared {@link Decoder}. |
| 54 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 55 | 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 Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 63 | /** |
| 64 | * Acquires a {@link Decoder} for the enclosing type. |
| 65 | * |
| 66 | * @return a possibly shared {@link Decoder}. |
| 67 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 68 | 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 Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 76 | /** |
| 77 | * Acquires a {@link Decoder} for the enclosing type. |
| 78 | * |
| 79 | * @return a possibly shared {@link Decoder}. |
| 80 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 81 | public static Decoder<Summary> decoder() { |
| 82 | return DECODER; |
| 83 | } |
| 84 | } |