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.nio.charset.StandardCharsets; |
| 6 | import java.util.List; |
| 7 | |
| 8 | /** |
| 9 | * A commit in an OSTree repository. |
| 10 | * |
| 11 | * <p>Has an optional parent, a root directory, and various metadata. |
| 12 | * |
| 13 | * <p>Reference: {@code ostree-core.h#OSTREE_COMMIT_GVARIANT_STRING} |
| 14 | */ |
| 15 | public record Commit( |
| 16 | Metadata metadata, |
| 17 | Checksum parentChecksum, |
| 18 | List<RelatedObject> relatedObjects, |
| 19 | String subject, |
| 20 | String body, |
| 21 | long timestamp, |
| 22 | Checksum rootDirTreeChecksum, |
| 23 | Checksum rootDirMetaChecksum) { |
| 24 | |
| 25 | public record RelatedObject(String ref, Checksum commitChecksum) { |
| 26 | |
| 27 | private static final Decoder<RelatedObject> DECODER = |
| 28 | Decoder.ofStructure( |
| 29 | RelatedObject.class, Decoder.ofString(StandardCharsets.UTF_8), Checksum.decoder()); |
| 30 | |
| 31 | public static Decoder<RelatedObject> decoder() { |
| 32 | return DECODER; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | private static final Decoder<Commit> DECODER = |
| 37 | Decoder.ofStructure( |
| 38 | Commit.class, |
| 39 | Metadata.decoder(), |
| 40 | Checksum.decoder(), |
| 41 | Decoder.ofArray(RelatedObject.decoder()), |
| 42 | Decoder.ofString(StandardCharsets.UTF_8), |
| 43 | Decoder.ofString(StandardCharsets.UTF_8), |
| 44 | Decoder.ofLong().withByteOrder(ByteOrder.BIG_ENDIAN), |
| 45 | Checksum.decoder(), |
| 46 | Checksum.decoder()); |
| 47 | |
| 48 | public static Decoder<Commit> decoder() { |
| 49 | return DECODER; |
| 50 | } |
| 51 | } |