Decoder: Make anonymous classes into named inner classes.

Change-Id: I3150b262512cafe42f139d56c9ecee165da4e1df
1 file changed
tree: ff72a4e4a2a3268464952f8841343a6bd4877b00
  1. .gitignore
  2. .mvn/
  3. COPYING
  4. COPYING.GPL
  5. README.md
  6. pom.xml
  7. src/
README.md

GVariant for Java

This library provides a GVariant parser in pure Java.

Overview

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.

Example

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));