Matthias Andreas Benkard | 4c32c39 | 2021-12-12 21:23:53 +0100 | [diff] [blame^] | 1 | /** |
| 2 | * Provides {@link eu.mulk.jgvariant.core.Value} and {@link eu.mulk.jgvariant.core.Decoder}, the |
| 3 | * foundational classes for <a href="https://docs.gtk.org/glib/struct.Variant.html">GVariant</a> |
| 4 | * parsing. |
| 5 | * |
| 6 | * <p>{@link eu.mulk.jgvariant.core.Value} is a sum type (sealed interface) that represents a |
| 7 | * GVariant value. Its subtypes represent the different types of values that GVariant supports. |
| 8 | * |
| 9 | * <p>Instances of {@link eu.mulk.jgvariant.core.Decoder} read a given concrete subtype of {@link |
| 10 | * eu.mulk.jgvariant.core.Value} from a {@link java.nio.ByteBuffer}. The class also contains factory |
| 11 | * methods to create those instances. |
| 12 | * |
| 13 | * <p><strong>Example</strong> |
| 14 | * |
| 15 | * <p>To parse a GVariant of type {@code "a(si)"}, which is an array of pairs of {@link String} and |
| 16 | * {@code int}, you can use the following code: |
| 17 | * |
| 18 | * <pre>{@code |
| 19 | * record ExampleRecord(Value.Str s, Value.Int32 i) {} |
| 20 | * |
| 21 | * var decoder = |
| 22 | * Decoder.ofArray( |
| 23 | * Decoder.ofStructure( |
| 24 | * ExampleRecord.class, |
| 25 | * Decoder.ofStr(UTF_8), |
| 26 | * Decoder.ofInt32().withByteOrder(LITTLE_ENDIAN))); |
| 27 | * |
| 28 | * byte[] bytes = ...; |
| 29 | * Value.Array<Value.Structure<ExampleRecord>> example = decoder.decode(ByteBuffer.wrap(bytes)); |
| 30 | * }</pre> |
| 31 | */ |
| 32 | package eu.mulk.jgvariant.core; |