Skip to content

Commit 87242bf

Browse files
committed
added annotation to provide way to mark class fields to be added as custom ones by DSLBuilder
1 parent ca3157b commit 87242bf

File tree

5 files changed

+365
-128
lines changed

5 files changed

+365
-128
lines changed

jbbp/src/main/java/com/igormaznitsa/jbbp/io/AbstractMappedClassFieldObserver.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.igormaznitsa.jbbp.exceptions.JBBPException;
2020
import com.igormaznitsa.jbbp.exceptions.JBBPIllegalArgumentException;
2121
import com.igormaznitsa.jbbp.mapper.Bin;
22+
import com.igormaznitsa.jbbp.utils.DslBinCustom;
2223
import com.igormaznitsa.jbbp.mapper.BinType;
2324
import com.igormaznitsa.jbbp.model.JBBPFieldInt;
2425
import com.igormaznitsa.jbbp.model.JBBPFieldLong;
@@ -148,7 +149,9 @@ protected void processObject(final Object obj, Field field, final Object customF
148149
field = ReflectUtils.makeAccessible(field);
149150

150151
final Bin clazzAnno = obj.getClass().getAnnotation(Bin.class);
152+
final DslBinCustom clazzCustomAnno = obj.getClass().getAnnotation(DslBinCustom.class);
151153
final Bin fieldAnno = field == null ? null : field.getAnnotation(Bin.class);
154+
final DslBinCustom fieldCustomAnno = field == null ? null : field.getAnnotation(DslBinCustom.class);
152155

153156
this.onStructStart(obj, field, clazzAnno == null ? fieldAnno : clazzAnno);
154157

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.igormaznitsa.jbbp.utils;
2+
3+
import com.igormaznitsa.jbbp.io.JBBPByteOrder;
4+
5+
import java.lang.annotation.ElementType;
6+
import java.lang.annotation.Inherited;
7+
import java.lang.annotation.Retention;
8+
import java.lang.annotation.RetentionPolicy;
9+
import java.lang.annotation.Target;
10+
11+
/**
12+
* Annotation allows to mark a field as custom data type for DSL builder.
13+
* @since 1.4.1
14+
* @see com.igormaznitsa.jbbp.utils.JBBPDslBuilder
15+
*/
16+
@Retention(RetentionPolicy.RUNTIME)
17+
@Target( {ElementType.FIELD, ElementType.TYPE})
18+
@Inherited
19+
public @interface DslBinCustom {
20+
/**
21+
* Name of the field.
22+
* @return name of the field, if empty then undefined
23+
*/
24+
String name() default "";
25+
26+
/**
27+
* Name of the custom type.
28+
* @return type of the field, if empty then undefined
29+
*/
30+
String type() default "";
31+
32+
/**
33+
* Byte order for the field.
34+
* @return byte order of data represented by the field
35+
*/
36+
JBBPByteOrder byteOrder() default JBBPByteOrder.BIG_ENDIAN;
37+
38+
/**
39+
* Expression to be placed in extra part of type. It means type[:extra]
40+
* @return extra value, if empty then undefined
41+
*/
42+
String extraExpression() default "";
43+
44+
/**
45+
* Expression to represent array size of the field.
46+
* @return array size of the field, if empty then not defined
47+
*/
48+
String arraySizeExpression() default "";
49+
50+
/**
51+
* Order of the field.
52+
* @return order of the field.
53+
*/
54+
int order() default 0;
55+
56+
/**
57+
* Field allows provide some comment.
58+
* @return comment for the annotation
59+
*/
60+
String comment() default "";
61+
}

0 commit comments

Comments
 (0)