Matthias Andreas Benkard | b5d657a | 2022-02-03 21:14:30 +0100 | [diff] [blame] | 1 | // SPDX-FileCopyrightText: © 2021 Matthias Andreas Benkard <code@mail.matthias.benkard.de> |
| 2 | // |
| 3 | // SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 | |
Matthias Andreas Benkard | 4c32c39 | 2021-12-12 21:23:53 +0100 | [diff] [blame] | 5 | /** |
Matthias Andreas Benkard | 55c3481 | 2021-12-14 21:51:10 +0100 | [diff] [blame] | 6 | * Provides {@link eu.mulk.jgvariant.core.Decoder}, the foundational class for <a |
| 7 | * href="https://docs.gtk.org/glib/struct.Variant.html">GVariant</a> parsing. |
Matthias Andreas Benkard | 4c32c39 | 2021-12-12 21:23:53 +0100 | [diff] [blame] | 8 | * |
Matthias Andreas Benkard | 55c3481 | 2021-12-14 21:51:10 +0100 | [diff] [blame] | 9 | * <p>Instances of {@link eu.mulk.jgvariant.core.Decoder} read a given value type from a {@link |
| 10 | * java.nio.ByteBuffer}. The class also contains factory methods to create those instances. |
Matthias Andreas Benkard | 4c32c39 | 2021-12-12 21:23:53 +0100 | [diff] [blame] | 11 | * |
| 12 | * <p><strong>Example</strong> |
| 13 | * |
Matthias Andreas Benkard | 35f7a20 | 2021-12-14 19:29:26 +0100 | [diff] [blame] | 14 | * <p>To parse a GVariant of type {@code "a(si)"}, which is an array of pairs of {@link |
| 15 | * java.lang.String} and {@code int}, you can use the following code: |
Matthias Andreas Benkard | 4c32c39 | 2021-12-12 21:23:53 +0100 | [diff] [blame] | 16 | * |
| 17 | * <pre>{@code |
Matthias Andreas Benkard | 35f7a20 | 2021-12-14 19:29:26 +0100 | [diff] [blame] | 18 | * record ExampleRecord(String s, int i) {} |
Matthias Andreas Benkard | 4c32c39 | 2021-12-12 21:23:53 +0100 | [diff] [blame] | 19 | * |
| 20 | * var decoder = |
| 21 | * Decoder.ofArray( |
| 22 | * Decoder.ofStructure( |
| 23 | * ExampleRecord.class, |
Matthias Andreas Benkard | 35f7a20 | 2021-12-14 19:29:26 +0100 | [diff] [blame] | 24 | * Decoder.ofString(UTF_8), |
| 25 | * Decoder.ofInt().withByteOrder(LITTLE_ENDIAN))); |
Matthias Andreas Benkard | 4c32c39 | 2021-12-12 21:23:53 +0100 | [diff] [blame] | 26 | * |
| 27 | * byte[] bytes = ...; |
Matthias Andreas Benkard | 35f7a20 | 2021-12-14 19:29:26 +0100 | [diff] [blame] | 28 | * List<ExampleRecord> example = decoder.decode(ByteBuffer.wrap(bytes)); |
Matthias Andreas Benkard | 4c32c39 | 2021-12-12 21:23:53 +0100 | [diff] [blame] | 29 | * }</pre> |
| 30 | */ |
| 31 | package eu.mulk.jgvariant.core; |