blob: 7f7dd23cc1c80c63b20f8ffeafc3a2b7d469c739 [file] [log] [blame]
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +01001package eu.mulk.jgvariant.ostree;
2
3import eu.mulk.jgvariant.core.Decoder;
4import java.nio.ByteOrder;
5import java.util.List;
6
7/**
Matthias Andreas Benkard05114642021-12-29 21:51:29 +01008 * 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 Benkard4e8423d2021-12-19 22:56:09 +010021 */
22public record DeltaPartPayload(
23 List<FileMode> fileModes,
24 List<List<Xattr>> xattrs,
25 ByteString rawDataSource,
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010026 List<DeltaOperation> operations) {
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010027
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 Benkard05114642021-12-29 21:51:29 +010034 ByteString.decoder().map(DeltaPartPayload::parseDeltaOperationList));
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010035
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010036 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 Benkard4e8423d2021-12-19 22:56:09 +010047 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 Benkard05114642021-12-29 21:51:29 +010056 /**
57 * Acquires a {@link Decoder} for the enclosing type.
58 *
59 * @return a possibly shared {@link Decoder}.
60 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010061 public static Decoder<FileMode> decoder() {
62 return DECODER;
63 }
64 }
65
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010066 /**
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 Benkard4e8423d2021-12-19 22:56:09 +010074 public static Decoder<DeltaPartPayload> decoder() {
75 return DECODER;
76 }
77}