Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 1 | package eu.mulk.jgvariant.ostree; |
| 2 | |
| 3 | import eu.mulk.jgvariant.core.Decoder; |
| 4 | import java.nio.ByteOrder; |
| 5 | import java.util.List; |
| 6 | |
| 7 | /** |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame^] | 8 | * A payload file from a static delta. |
| 9 | * |
| 10 | * <p>The first byte is a compression byte: {@code 0} for none, {@code 'x'} for LZMA. The actual |
| 11 | * GVariant data begins right after. |
| 12 | * |
| 13 | * <p>Reference: {@code |
| 14 | * ostree-repo-static-delta-private.h#OSTREE_STATIC_DELTA_PART_PAYLOAD_FORMAT_V0} |
| 15 | * |
| 16 | * @param fileModes the {@link FileMode}s of the files generated by this delta payload. |
| 17 | * @param xattrs the {@link Xattr}s of the files generated by this delta payload. |
| 18 | * @param rawDataSource the data bytes used in the delta operations. |
| 19 | * @param operations the operations to apply during delta patching. |
| 20 | * @see DeltaSuperblock |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 21 | */ |
| 22 | public record DeltaPartPayload( |
| 23 | List<FileMode> fileModes, |
| 24 | List<List<Xattr>> xattrs, |
| 25 | ByteString rawDataSource, |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame^] | 26 | List<DeltaOperation> operations) { |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 27 | |
| 28 | private static final Decoder<DeltaPartPayload> DECODER = |
| 29 | Decoder.ofStructure( |
| 30 | DeltaPartPayload.class, |
| 31 | Decoder.ofArray(FileMode.decoder()), |
| 32 | Decoder.ofArray(Decoder.ofArray(Xattr.decoder())), |
| 33 | ByteString.decoder(), |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame^] | 34 | ByteString.decoder().map(DeltaPartPayload::parseDeltaOperationList)); |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 35 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame^] | 36 | private static List<DeltaOperation> parseDeltaOperationList(ByteString byteString) { |
| 37 | return byteString.stream().map(DeltaOperation::valueOf).toList(); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * A file mode triple (UID, GID, and permission bits). |
| 42 | * |
| 43 | * @param uid |
| 44 | * @param gid |
| 45 | * @param mode |
| 46 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 47 | public record FileMode(int uid, int gid, int mode) { |
| 48 | |
| 49 | private static final Decoder<FileMode> DECODER = |
| 50 | Decoder.ofStructure( |
| 51 | FileMode.class, |
| 52 | Decoder.ofInt().withByteOrder(ByteOrder.LITTLE_ENDIAN), |
| 53 | Decoder.ofInt().withByteOrder(ByteOrder.LITTLE_ENDIAN), |
| 54 | Decoder.ofInt().withByteOrder(ByteOrder.LITTLE_ENDIAN)); |
| 55 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame^] | 56 | /** |
| 57 | * Acquires a {@link Decoder} for the enclosing type. |
| 58 | * |
| 59 | * @return a possibly shared {@link Decoder}. |
| 60 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 61 | public static Decoder<FileMode> decoder() { |
| 62 | return DECODER; |
| 63 | } |
| 64 | } |
| 65 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame^] | 66 | /** |
| 67 | * Acquires a {@link Decoder} for the enclosing type. |
| 68 | * |
| 69 | * <p>FIXME: The first byte is actually a compression byte: {@code 0} for none, {@code 'x'} for |
| 70 | * LZMA. |
| 71 | * |
| 72 | * @return a possibly shared {@link Decoder}. |
| 73 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 74 | public static Decoder<DeltaPartPayload> decoder() { |
| 75 | return DECODER; |
| 76 | } |
| 77 | } |