blob: c1f2701e8d05970dea3aa1066a64ba942ee9cc65 [file] [log] [blame]
Matthias Andreas Benkard05114642021-12-29 21:51:29 +01001package eu.mulk.jgvariant.ostree;
2
3import static org.apiguardian.api.API.Status.STABLE;
4
5import org.apiguardian.api.API;
6
7/** An operation in a static delta. */
8@API(status = STABLE)
9public enum DeltaOperation {
10 OPEN_SPLICE_AND_CLOSE((byte) 'S'),
11 OPEN((byte) 'o'),
12 WRITE((byte) 'w'),
13 SET_READ_SOURCE((byte) 'r'),
14 UNSET_READ_SOURCE((byte) 'R'),
15 CLOSE((byte) 'c'),
16 BSPATCH((byte) 'B');
17
18 private final byte byteValue;
19
20 DeltaOperation(byte byteValue) {
21 this.byteValue = byteValue;
22 }
23
24 /**
25 * The serialized byte value.
26 *
27 * @return a serialized byte value for use in GVariant structures.
28 */
29 public byte byteValue() {
30 return byteValue;
31 }
32
33 /**
34 * Returns the {@link DeltaOperation} corresponding to a serialized GVariant value.
35 *
36 * @param byteValue a serialized value as used in GVariant.
37 * @return the {@link DeltaOperation} corresponding to the serialized value.
38 * @throws IllegalArgumentException if the byte value is invalid.
39 */
40 public static DeltaOperation valueOf(byte byteValue) {
41 return switch (byteValue) {
42 case (byte) 'S' -> OPEN_SPLICE_AND_CLOSE;
43 case (byte) 'o' -> OPEN;
44 case (byte) 'w' -> WRITE;
45 case (byte) 'r' -> SET_READ_SOURCE;
46 case (byte) 'R' -> UNSET_READ_SOURCE;
47 case (byte) 'c' -> CLOSE;
48 case (byte) 'B' -> BSPATCH;
49 default -> throw new IllegalArgumentException(
50 "invalid DeltaOperation: %d".formatted(byteValue));
51 };
52 }
53}