Skip to content

Commit a98fe44

Browse files
committed
added test and improved comments
1 parent 7c7716c commit a98fe44

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

jbbp/src/main/java/com/igormaznitsa/jbbp/mapper/Bin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@
8585
boolean custom() default false;
8686

8787
/**
88-
* The Filed contains some extra text info which can be used by a custom field
89-
* processor, the engine doesn't use the field.
88+
* The Field is used by custom field processor and as expression to calculate array length.
9089
*
9190
* @return the extra field as String
9291
* @see JBBPMapperCustomFieldProcessor

jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPDslBuilder.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,21 +1550,26 @@ protected BinFieldContainer collectAnnotatedFields(final Class<?> annotatedClass
15501550

15511551
/**
15521552
* Convert an annotated class into its JBBP DSL representation.
1553+
* <b>NB!</b> the method creates structure bases on class name, so that it can't be used for auto-mapping
1554+
* if you want use auto-mapping, use {@link JBBPDslBuilder#AnnotatedClassFields(Class)}
15531555
*
15541556
* @param annotatedClass class to be converted into JBBP script, must not be null
15551557
* @return the builder instance, must not be null
1556-
* @see com.igormaznitsa.jbbp.mapper.Bin
1558+
* @see JBBPDslBuilder#AnnotatedClassFields(Class)
15571559
*/
15581560
public JBBPDslBuilder AnnotatedClass(final Class<?> annotatedClass) {
15591561
return addAnnotatedClass(annotatedClass, false);
15601562
}
15611563

15621564
/**
15631565
* Add just fields of annotated class, outbound class will not be added as structure.
1566+
* <b>The Method allows to prepare script which will be able make mapping of field values</b>
15641567
*
15651568
* @param annotatedClass class to be converted into JBBP script, must not be null
15661569
* @return the builder instance, must not be null
1570+
* @see com.igormaznitsa.jbbp.model.JBBPFieldStruct#mapTo
15671571
* @see com.igormaznitsa.jbbp.mapper.Bin
1572+
* @see JBBPDslBuilder#AnnotatedClass(Class)
15681573
*/
15691574
public JBBPDslBuilder AnnotatedClassFields(final Class<?> annotatedClass) {
15701575
return addAnnotatedClass(annotatedClass, true);

jbbp/src/test/java/com/igormaznitsa/jbbp/it/BasedOnQuestionsAndCasesTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import com.igormaznitsa.jbbp.model.JBBPFieldLong;
3434
import com.igormaznitsa.jbbp.model.JBBPFieldStruct;
3535
import com.igormaznitsa.jbbp.model.JBBPNumericField;
36+
import com.igormaznitsa.jbbp.utils.JBBPDslBuilder;
37+
import com.igormaznitsa.jbbp.utils.JBBPTextWriter;
3638
import org.junit.jupiter.api.Test;
3739

3840
import java.io.EOFException;
@@ -222,6 +224,22 @@ public void run() {
222224
assertEquals(0, errorCounter.get());
223225
}
224226

227+
@Test
228+
public void testParseBitsThroughDslBasedScriptAndMapping() throws Exception {
229+
class Bits {
230+
@Bin(name = "a", type = BinType.BIT_ARRAY, outBitNumber = JBBPBitNumber.BITS_1, extra = "_")
231+
byte[] bit;
232+
}
233+
234+
JBBPParser parser = JBBPParser.prepare(JBBPDslBuilder.Begin().AnnotatedClassFields(Bits.class).End());
235+
236+
Bits parsed = parser.parse(new byte[] {73}).mapTo(Bits.class);
237+
238+
System.out.println(JBBPTextWriter.makeStrWriter().Bin(parsed).Close().toString());
239+
240+
assertArrayEquals(new byte[] {1, 0, 0, 1, 0, 0, 1, 0}, parsed.bit);
241+
}
242+
225243
/**
226244
* Case 10-aug-2017
227245
* NullPointer exception when referencing a JBBPCustomFieldTypeProcessor parsed field.

0 commit comments

Comments
 (0)