blob: b489cf077c17ec227ffe18fe4889bd3bbd68fdac [file] [log] [blame]
Matthias Andreas Benkardb5d657a2022-02-03 21:14:30 +01001// SPDX-FileCopyrightText: © 2021 Matthias Andreas Benkard <code@mail.matthias.benkard.de>
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
Matthias Andreas Benkardc981cde2021-12-30 20:37:39 +01005package eu.mulk.jgvariant.ostree;
6
7enum DeltaOperationType {
8 OPEN_SPLICE_AND_CLOSE((byte) 'S'),
9 OPEN((byte) 'o'),
10 WRITE((byte) 'w'),
11 SET_READ_SOURCE((byte) 'r'),
12 UNSET_READ_SOURCE((byte) 'R'),
13 CLOSE((byte) 'c'),
14 BSPATCH((byte) 'B');
15
16 private final byte byteValue;
17
18 DeltaOperationType(byte byteValue) {
19 this.byteValue = byteValue;
20 }
21
22 /**
23 * The serialized byte value.
24 *
25 * @return a serialized byte value for use in GVariant structures.
26 */
27 byte byteValue() {
28 return byteValue;
29 }
30
31 /**
32 * Returns the {@link DeltaOperationType} corresponding to a serialized GVariant value.
33 *
34 * @param byteValue a serialized value as used in GVariant.
35 * @return the {@link DeltaOperationType} corresponding to the serialized value.
36 * @throws IllegalArgumentException if the byte value is invalid.
37 */
38 static DeltaOperationType valueOf(byte byteValue) {
39 return switch (byteValue) {
40 case (byte) 'S' -> OPEN_SPLICE_AND_CLOSE;
41 case (byte) 'o' -> OPEN;
42 case (byte) 'w' -> WRITE;
43 case (byte) 'r' -> SET_READ_SOURCE;
44 case (byte) 'R' -> UNSET_READ_SOURCE;
45 case (byte) 'c' -> CLOSE;
46 case (byte) 'B' -> BSPATCH;
47 default -> throw new IllegalArgumentException(
48 "invalid DeltaOperation: %d".formatted(byteValue));
49 };
50 }
51}