commit | 35f7a20b22271f8f28d15da8df85cff2fc9cd716 | [log] [tgz] |
---|---|---|
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | Tue Dec 14 19:29:26 2021 +0100 |
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | Tue Dec 14 19:29:26 2021 +0100 |
tree | 496e011fd0cf8c34d2634ce991f287b6a4ee4838 | |
parent | 4c32c3998476e12c34984d52253eaa4ae3bf6769 [diff] |
Simplify types, replace Value with Variant. Change-Id: I2e492ebfefc7e9a47c874ed22ff199412e9948ee
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));