Matthias Andreas Benkard | c981cde | 2021-12-30 20:37:39 +0100 | [diff] [blame] | 1 | package eu.mulk.jgvariant.ostree; |
| 2 | |
| 3 | enum DeltaOperationType { |
| 4 | OPEN_SPLICE_AND_CLOSE((byte) 'S'), |
| 5 | OPEN((byte) 'o'), |
| 6 | WRITE((byte) 'w'), |
| 7 | SET_READ_SOURCE((byte) 'r'), |
| 8 | UNSET_READ_SOURCE((byte) 'R'), |
| 9 | CLOSE((byte) 'c'), |
| 10 | BSPATCH((byte) 'B'); |
| 11 | |
| 12 | private final byte byteValue; |
| 13 | |
| 14 | DeltaOperationType(byte byteValue) { |
| 15 | this.byteValue = byteValue; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * The serialized byte value. |
| 20 | * |
| 21 | * @return a serialized byte value for use in GVariant structures. |
| 22 | */ |
| 23 | byte byteValue() { |
| 24 | return byteValue; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Returns the {@link DeltaOperationType} corresponding to a serialized GVariant value. |
| 29 | * |
| 30 | * @param byteValue a serialized value as used in GVariant. |
| 31 | * @return the {@link DeltaOperationType} corresponding to the serialized value. |
| 32 | * @throws IllegalArgumentException if the byte value is invalid. |
| 33 | */ |
| 34 | static DeltaOperationType valueOf(byte byteValue) { |
| 35 | return switch (byteValue) { |
| 36 | case (byte) 'S' -> OPEN_SPLICE_AND_CLOSE; |
| 37 | case (byte) 'o' -> OPEN; |
| 38 | case (byte) 'w' -> WRITE; |
| 39 | case (byte) 'r' -> SET_READ_SOURCE; |
| 40 | case (byte) 'R' -> UNSET_READ_SOURCE; |
| 41 | case (byte) 'c' -> CLOSE; |
| 42 | case (byte) 'B' -> BSPATCH; |
| 43 | default -> throw new IllegalArgumentException( |
| 44 | "invalid DeltaOperation: %d".formatted(byteValue)); |
| 45 | }; |
| 46 | } |
| 47 | } |