commit | 34430180f83a9e52ead4f919731f955bbc3b3b79 | [log] [tgz] |
---|---|---|
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | Tue Dec 14 20:00:36 2021 +0100 |
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | Tue Dec 14 20:00:36 2021 +0100 |
tree | ff72a4e4a2a3268464952f8841343a6bd4877b00 | |
parent | 35f7a20b22271f8f28d15da8df85cff2fc9cd716 [diff] |
Decoder: Make anonymous classes into named inner classes. Change-Id: I3150b262512cafe42f139d56c9ecee165da4e1df
This library provides a GVariant parser in pure Java.
The two foundational classes are Value
and Decoder
.
Value
is a sum type (sealed interface) that represents a GVariant value. Its subtypes represent the different types of values that GVariant supports.
Instances of Decoder
read a given concrete subtype of Value
from a ByteBuffer. The class also contains factory methods to create those instances.
The various subclasses of Decoder
together implement the GVariant serialization specification.
To parse a GVariant value of type "a(si)"
, which is an array of pairs of String and int
, you can use the following code:
record ExampleRecord(String s, int i) {} var decoder = Decoder.ofArray( Decoder.ofStructure( ExampleRecord.class, Decoder.ofString(StandardCharsets.UTF_8), Decoder.ofInt().withByteOrder(ByteOrder.LITTLE_ENDIAN))); byte[] bytes = ...; List<ExampleRecord> example = decoder.decode(ByteBuffer.wrap(bytes));