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.charset.StandardCharsets; |
| 5 | import java.util.List; |
| 6 | |
| 7 | /** |
| 8 | * Metadata describing files and directories of a file tree. |
| 9 | * |
| 10 | * <p>Referenced by {@link Commit#rootDirTreeChecksum()} and recursively by {@link |
| 11 | * Directory#treeChecksum()}. |
| 12 | * |
| 13 | * <p>Reference: {@code ostree-core.h#OSTREE_TREE_GVARIANT_STRING} |
| 14 | */ |
| 15 | public record DirTree(List<File> files, List<Directory> directories) { |
| 16 | |
| 17 | public record File(String name, Checksum checksum) { |
| 18 | |
| 19 | private static final Decoder<File> DECODER = |
| 20 | Decoder.ofStructure( |
| 21 | File.class, Decoder.ofString(StandardCharsets.UTF_8), Checksum.decoder()); |
| 22 | |
| 23 | public static Decoder<File> decoder() { |
| 24 | return DECODER; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | public record Directory(String name, Checksum treeChecksum, Checksum dirChecksum) { |
| 29 | |
| 30 | private static final Decoder<Directory> DECODER = |
| 31 | Decoder.ofStructure( |
| 32 | Directory.class, |
| 33 | Decoder.ofString(StandardCharsets.UTF_8), |
| 34 | Checksum.decoder(), |
| 35 | Checksum.decoder()); |
| 36 | |
| 37 | public static Decoder<Directory> decoder() { |
| 38 | return DECODER; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | private static final Decoder<DirTree> DECODER = |
| 43 | Decoder.ofStructure( |
| 44 | DirTree.class, Decoder.ofArray(File.decoder()), Decoder.ofArray(Directory.decoder())); |
| 45 | |
| 46 | public static Decoder<DirTree> decoder() { |
| 47 | return DECODER; |
| 48 | } |
| 49 | } |