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 | |
| 10 | /** |
| 11 | * A fallback entry in a {@link DeltaSuperblock}. |
| 12 | * |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 13 | * <p>References a file in the OSTree repository. |
| 14 | * |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 15 | * <p>Reference: {@code ostree-repo-static-delta-private.h#OSTREE_STATIC_DELTA_FALLBACK_FORMAT} |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 16 | * |
| 17 | * @param objectType the object type of the file represented by this fallback entry. |
| 18 | * @param checksum the checksum of the file represented by this fallback entry. |
| 19 | * @param compressedSize the compressed size of the file represented by this fallback entry. |
| 20 | * @param uncompressedSize the uncompressed size of the file represented by this fallback entry. |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 21 | */ |
| 22 | public record DeltaFallback( |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 23 | ObjectType objectType, Checksum checksum, long compressedSize, long uncompressedSize) { |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 24 | |
| 25 | private static final Decoder<DeltaFallback> DECODER = |
| 26 | Decoder.ofStructure( |
| 27 | DeltaFallback.class, |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 28 | Decoder.ofByte().map(ObjectType::valueOf), |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 29 | Checksum.decoder(), |
Matthias Andreas Benkard | a8514a3 | 2021-12-30 21:01:48 +0100 | [diff] [blame] | 30 | Decoder.ofLong(), |
| 31 | Decoder.ofLong()); |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 32 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 33 | /** |
| 34 | * Acquires a {@link Decoder} for the enclosing type. |
| 35 | * |
Matthias Andreas Benkard | a8514a3 | 2021-12-30 21:01:48 +0100 | [diff] [blame] | 36 | * <p><strong>Note:</strong> This decoder has an unspecified {@link ByteOrder}. |
| 37 | * |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 38 | * @return a possibly shared {@link Decoder}. |
| 39 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 40 | public static Decoder<DeltaFallback> decoder() { |
| 41 | return DECODER; |
| 42 | } |
Matthias Andreas Benkard | a8514a3 | 2021-12-30 21:01:48 +0100 | [diff] [blame] | 43 | |
| 44 | DeltaFallback byteSwapped() { |
| 45 | return new DeltaFallback(objectType, checksum, compressedSize, uncompressedSize); |
| 46 | } |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 47 | } |