Skip to content

Commit f7096c2

Browse files
committed
Feat: Complete Decoder implementation, refactor Encoder, add TypeConverter functionality
- Refactored `StructEncoder` for better maintainability and performance. - Fully implemented `StructDecoder` for decoding structures from byte arrays. - Introduced `TypeConverterHelper` functionality for robust type conversion between various types, including null value handling, primitives, and complex objects. - Ensured consistent handling of null and default values across both Encoder and Decoder components. - Added comprehensive tests for all new features, including type conversion validation and edge cases.
1 parent 1d037e5 commit f7096c2

54 files changed

Lines changed: 3019 additions & 851 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/net/deanly/structlayout/StructLayout.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package net.deanly.structlayout;
22

33
import net.deanly.structlayout.analysis.HexDumpUtil;
4-
import net.deanly.structlayout.codec.StructEncoder;
5-
import net.deanly.structlayout.codec.StructDecoder;
4+
import net.deanly.structlayout.codec.encode.StructEncoder;
5+
import net.deanly.structlayout.codec.decode.StructDecoder;
66

77
public class StructLayout {
88

src/main/java/net/deanly/structlayout/analysis/CachedLayoutProvider.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,17 @@ public class CachedLayoutProvider {
4646
}
4747

4848
/**
49-
* 주어진 DataType에 맞는 Layout을 가져옵니다.
49+
* Retrieves a Layout instance corresponding to the specified DataType. If the layout
50+
* instance is not already cached, it will attempt to create a new instance using the
51+
* layout class provided by the DataType.
5052
*
51-
* @param dataType DataType (엔디안을 포함한 데이터 타입)
52-
* @return Layout<T> 인스턴스
53+
* @param <T> The type of the value being processed by the Layout.
54+
* @param dataType The DataType for which the Layout needs to be retrieved.
55+
* Must not be null and must provide a valid layout definition.
56+
* @return A Layout instance associated with the specified DataType.
57+
* Never null unless an unexpected error occurs.
58+
* @throws LayoutInitializationException If the Layout cannot be instantiated or
59+
* there is an error during initialization.
5360
*/
5461
@SuppressWarnings("unchecked")
5562
public static <T> Layout<T> getLayout(DataType dataType) {

src/main/java/net/deanly/structlayout/analysis/StructAnalyzer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
import java.lang.reflect.Modifier;
1212
import java.util.Collection;
1313

14+
/**
15+
* The StructAnalyzer class provides utilities to compute the total size of an
16+
* object based on its annotated fields. It processes fields annotated with
17+
* specific annotations, including {@code StructField}, {@code SequenceField},
18+
* and {@code StructObjectField}, to calculate the byte layout of an object
19+
* for structured serialization or other purposes.
20+
*/
1421
public class StructAnalyzer {
1522

1623
/**

src/main/java/net/deanly/structlayout/annotation/SequenceField.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,38 @@
77
import java.lang.annotation.RetentionPolicy;
88
import java.lang.annotation.Target;
99

10+
/**
11+
* Annotation to define a sequence field within a structured layout.
12+
* It targets fields that are part of a sequence with multiple elements
13+
* and optionally specifies the type of length prefix and element data types.
14+
*/
1015
@Retention(RetentionPolicy.RUNTIME)
1116
@Target(ElementType.FIELD)
1217
public @interface SequenceField {
18+
1319
/**
14-
* Field's order in the structure
20+
* Specifies the order of the field within a structured object or layout.
21+
* The order determines the sequence in which the field will be processed,
22+
* serialized, or deserialized in relation to other fields.
23+
*
24+
* @return the order of the field
1525
*/
1626
int order();
1727

1828
/**
19-
* The data type of the length prefix, indicating the number of elements in the sequence.
20-
* If null, no length prefix is used.
29+
* Specifies the data type of the length prefix for a sequence field.
30+
* This determines how the length of the sequence is represented, utilizing
31+
* a specific data type from the {@link DataType} enum.
32+
*
33+
* @return the data type used to represent the length of the sequence,
34+
* with the default being {@code DataType.UINT32_LE}.
2135
*/
2236
DataType lengthType() default DataType.UINT32_LE; // Default length type (nullable)
2337

2438
/**
25-
* Specifies the sequence element type using the Type enum.
39+
* Specifies the data type of the elements in the sequence.
40+
*
41+
* @return the data type of elements, as defined by the {@link DataType} enum
2642
*/
2743
DataType elementType(); // Type of the elements in the sequence
2844

src/main/java/net/deanly/structlayout/codec/StructDecoder.java

Lines changed: 0 additions & 202 deletions
This file was deleted.

0 commit comments

Comments
 (0)