Skip to content

Commit 1d03269

Browse files
committed
renamed fields of @bin, removed prefix 'out'
1 parent 768e6e2 commit 1d03269

File tree

16 files changed

+319
-296
lines changed

16 files changed

+319
-296
lines changed

jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/conversion/JBBPToJavaConverter.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ public void visitStructureStart(final int offsetInCompiledBlock, final JBBPByteO
388388
if (nullableArraySize == null) {
389389
structType = structBaseTypeName;
390390
if (this.builder.generateFields) {
391-
printField(nullableNameFieldInfo, byteOrder, false, getCurrentStruct().getFields().indent(), null, fieldModifier, structType, structName);
391+
printField(nullableNameFieldInfo, byteOrder, false, offsetInCompiledBlock, getCurrentStruct().getFields().indent(), null, fieldModifier, structType, structName);
392392
}
393393

394394
processSkipRemainingFlag();
@@ -401,7 +401,7 @@ public void visitStructureStart(final int offsetInCompiledBlock, final JBBPByteO
401401
} else {
402402
structType = structBaseTypeName + " []";
403403
if (this.builder.generateFields) {
404-
printField(nullableNameFieldInfo, byteOrder, true, getCurrentStruct().getFields().indent(), null, fieldModifier, structType, structName);
404+
printField(nullableNameFieldInfo, byteOrder, true, offsetInCompiledBlock, getCurrentStruct().getFields().indent(), null, fieldModifier, structType, structName);
405405
}
406406
processSkipRemainingFlag();
407407
processSkipRemainingFlagForWriting("this." + structName);
@@ -486,7 +486,12 @@ public void visitStructureEnd(final int offsetInCompiledBlock, final JBBPNamedFi
486486
}
487487

488488
@Override
489-
public void visitValField(final int offsetInCompiledBlock, final JBBPByteOrder byteOrder, final JBBPNamedFieldInfo nameFieldInfo, final JBBPIntegerValueEvaluator expression) {
489+
public void visitValField(
490+
final int offsetInCompiledBlock,
491+
final JBBPByteOrder byteOrder,
492+
final JBBPNamedFieldInfo nameFieldInfo,
493+
final JBBPIntegerValueEvaluator expression
494+
) {
490495
final String fieldName = prepFldName(nameFieldInfo.getFieldName());
491496
FieldType type = FieldType.VAL;
492497

@@ -505,7 +510,7 @@ public void visitValField(final int offsetInCompiledBlock, final JBBPByteOrder b
505510
getCurrentStruct().getFields().printf("@Bin(name=\"%s\")", nameFieldInfo.getFieldName());
506511
}
507512
}
508-
printField(nameFieldInfo, byteOrder, false, getCurrentStruct().getFields(), FieldType.VAL, fieldModifier, textFieldType, fieldName);
513+
printField(nameFieldInfo, byteOrder, false, offsetInCompiledBlock, getCurrentStruct().getFields(), FieldType.VAL, fieldModifier, textFieldType, fieldName);
509514
}
510515

511516
final String valIn = evaluatorToString(NAME_INPUT_STREAM, offsetInCompiledBlock, expression, this.flagSet, false);
@@ -522,6 +527,7 @@ public void visitValField(final int offsetInCompiledBlock, final JBBPByteOrder b
522527
private void printField(final JBBPNamedFieldInfo nullableFieldInfo,
523528
final JBBPByteOrder byteOrder,
524529
final boolean array,
530+
final int fieldOrder,
525531
final JavaSrcTextBuffer buffer,
526532
final FieldType nullableFieldType,
527533
final String modifier,
@@ -534,22 +540,23 @@ private void printField(final JBBPNamedFieldInfo nullableFieldInfo,
534540
|| nullableFieldType.getBinType() == BinType.UNDEFINED
535541
|| nullableFieldType.getBinTypeArray() == BinType.UNDEFINED) {
536542
if (binName == null) {
537-
buffer.printf("@Bin(outByteOrder=JBBPByteOrder.%s)%n", byteOrder.name());
543+
buffer.printf("@Bin(byteOrder=JBBPByteOrder.%s,order=%s)%n", byteOrder.name(), Integer.toString(fieldOrder));
538544
} else {
539-
buffer.printf("@Bin(name=\"%s\",outByteOrder=JBBPByteOrder.%s)%n", binName, byteOrder.name());
545+
buffer.printf("@Bin(name=\"%s\",byteOrder=JBBPByteOrder.%s,order=%s)%n", binName, byteOrder.name(), Integer.toString(fieldOrder));
540546
}
541547
} else {
542548
if (binName == null) {
543-
buffer.printf("@Bin(type=BinType.%s,outByteOrder=JBBPByteOrder.%s)%n", array ? nullableFieldType.getBinTypeArray() : nullableFieldType.getBinType(), byteOrder.name());
549+
buffer.printf("@Bin(type=BinType.%s,byteOrder=JBBPByteOrder.%s,order=%s)%n", array ? nullableFieldType.getBinTypeArray() : nullableFieldType.getBinType(), byteOrder.name(), Integer.toString(fieldOrder));
544550
} else {
545-
buffer.printf("@Bin(name=\"%s\",type=BinType.%s,outByteOrder=JBBPByteOrder.%s)%n", binName, array ? nullableFieldType.getBinTypeArray() : nullableFieldType.getBinType(), byteOrder.name());
551+
buffer.printf("@Bin(name=\"%s\",type=BinType.%s,byteOrder=JBBPByteOrder.%s,order=%s)%n", binName, array ? nullableFieldType.getBinTypeArray() : nullableFieldType.getBinType(), byteOrder.name(), Integer.toString(fieldOrder));
546552
}
547553
}
548554
}
549555
buffer.printf("%s %s %s;%n", modifier, type, name);
550556
}
551557

552558
private void printBitField(final boolean array,
559+
final int fieldOrder,
553560
final JBBPByteOrder byteOrder,
554561
final JBBPNamedFieldInfo nullableFieldInfo,
555562
final String sizeOfFieldOut,
@@ -560,14 +567,16 @@ private void printBitField(final boolean array,
560567
if (this.builder.addBinAnnotations) {
561568
final String binName = nullableFieldInfo == null ? null : nullableFieldInfo.getFieldName();
562569
if (binName == null) {
563-
buffer.printf("@Bin(type=BinType.%s,outBitNumber=%s,outByteOrder=JBBPByteOrder.%s)%n",
570+
buffer.printf("@Bin(type=BinType.%s,bitNumber=%s,byteOrder=JBBPByteOrder.%s,order=%s)%n",
564571
(array ? BinType.BIT_ARRAY : BinType.BIT).name(),
565-
sizeOfFieldOut, byteOrder.name());
572+
sizeOfFieldOut, byteOrder.name(),
573+
Integer.toString(fieldOrder));
566574
} else {
567-
buffer.printf("@Bin(name=\"%s\",type=BinType.%s,outBitNumber=%s,outByteOrder=JBBPByteOrder.%s)%n",
575+
buffer.printf("@Bin(name=\"%s\",type=BinType.%s,bitNumber=%s,byteOrder=JBBPByteOrder.%s,order=%s)%n",
568576
binName,
569577
(array ? BinType.BIT_ARRAY : BinType.BIT).name(),
570-
sizeOfFieldOut, byteOrder.name());
578+
sizeOfFieldOut, byteOrder.name(),
579+
Integer.toString(fieldOrder));
571580
}
572581
}
573582
buffer.printf("%s %s %s;%n", modifier, type, name);
@@ -619,6 +628,7 @@ public void visitPrimitiveField(
619628
nullableNameFieldInfo,
620629
byteOrder,
621630
false,
631+
offsetInCompiledBlock,
622632
getCurrentStruct().getFields(),
623633
type,
624634
fieldModifier,
@@ -631,7 +641,7 @@ public void visitPrimitiveField(
631641
} else {
632642
textFieldType = type.asJavaArrayFieldType() + " []";
633643
if (this.builder.generateFields) {
634-
printField(nullableNameFieldInfo, byteOrder, true, getCurrentStruct().getFields(), type, fieldModifier, textFieldType, fieldName);
644+
printField(nullableNameFieldInfo, byteOrder, true, offsetInCompiledBlock, getCurrentStruct().getFields(), type, fieldModifier, textFieldType, fieldName);
635645
}
636646
getCurrentStruct().getReadFunc().printf("this.%s = %s;%n", fieldName, type.makeReaderForArray(NAME_INPUT_STREAM, arraySizeIn, byteOrder));
637647
if (readWholeStreamAsArray) {
@@ -725,6 +735,7 @@ public void visitBitField(final int offsetInCompiledBlock, final JBBPByteOrder b
725735
if (this.builder.generateFields) {
726736
printBitField(
727737
nullableArraySize != null,
738+
offsetInCompiledBlock,
728739
byteOrder,
729740
nullableNameFieldInfo,
730741
sizeOfFieldOut,
@@ -846,7 +857,7 @@ public void visitVarField(
846857
if (readWholeStreamIntoArray || nullableArraySizeEvaluator != null) {
847858
fieldType = "JBBPAbstractArrayField<? extends JBBPAbstractField>";
848859
if (this.builder.generateFields) {
849-
printField(nullableNameFieldInfo, byteOrder, true, getCurrentStruct().getFields(), FieldType.VAR, fieldModifier, fieldType, fieldName);
860+
printField(nullableNameFieldInfo, byteOrder, true, offsetInCompiledBlock, getCurrentStruct().getFields(), FieldType.VAR, fieldModifier, fieldType, fieldName);
850861
}
851862

852863
this.getCurrentStruct().getReadFunc().printf("%s = %s;%n",
@@ -873,7 +884,7 @@ public void visitVarField(
873884
} else {
874885
fieldType = "JBBPAbstractField";
875886
if (this.builder.generateFields) {
876-
printField(nullableNameFieldInfo, byteOrder, false, getCurrentStruct().getFields(), FieldType.VAR, fieldModifier, fieldType, fieldName);
887+
printField(nullableNameFieldInfo, byteOrder, false, offsetInCompiledBlock, getCurrentStruct().getFields(), FieldType.VAR, fieldModifier, fieldType, fieldName);
877888
}
878889

879890
this.getCurrentStruct().getReadFunc().printf("%s = %s;%n",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected void processObjectField(final Object obj, final MappedFieldRecord fiel
132132

133133
switch (type) {
134134
case BIT: {
135-
final JBBPBitNumber bitNumber = annotation.outBitNumber();
135+
final JBBPBitNumber bitNumber = annotation.bitNumber();
136136
if (fieldType == boolean.class) {
137137
this.onFieldBits(obj, field, annotation, bitNumber, ((Boolean) readFieldValue(obj, fieldRecord)) ? 0xFF : 0x00);
138138
} else {
@@ -248,7 +248,7 @@ protected void processObjectField(final Object obj, final MappedFieldRecord fiel
248248
final int len = Array.getLength(array);
249249
this.onArrayStart(obj, field, annotation, len);
250250

251-
final JBBPBitNumber bitNumber = annotation.outBitNumber();
251+
final JBBPBitNumber bitNumber = annotation.bitNumber();
252252

253253
if (fieldType.getComponentType() == boolean.class) {
254254
for (int i = 0; i < len; i++) {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ protected void assertNotEnded() {
996996

997997
/**
998998
* Save fields of an object marked by Bin annotation. Fields will be ordered
999-
* through {@link Bin#outOrder()} field, NB! By default Java doesn't keep field
999+
* through {@link Bin#order()} field, NB! By default Java doesn't keep field
10001000
* outOrder. Ordered fields of class will be saved into internal cache for speed
10011001
* but the cache can be reset through {@link JBBPMapper#clearFieldCache()}
10021002
*
@@ -1013,7 +1013,7 @@ public JBBPOut Bin(final Object object) throws IOException {
10131013

10141014
/**
10151015
* Save fields of an object marked by Bin annotation. Fields will be ordered
1016-
* through {@link Bin#outOrder()} field, NB! By default Java doesn't keep field
1016+
* through {@link Bin#order()} field, NB! By default Java doesn't keep field
10171017
* outOrder. Ordered fields of class will be saved into internal cache for speed
10181018
* but the cache can be reset through {@link JBBPMapper#clearFieldCache()}
10191019
*
@@ -1038,7 +1038,7 @@ public JBBPOut Bin(final Object object, final JBBPCustomFieldWriter customFieldW
10381038
protected void onFieldFloat(final Object obj, final Field field, final Bin annotation, final float value) {
10391039
final JBBPByteOrder old = this.byteOrder;
10401040
try {
1041-
this.byteOrder = annotation.outByteOrder();
1041+
this.byteOrder = annotation.byteOrder();
10421042
this.Float(value);
10431043
} catch (IOException ex) {
10441044
throw new JBBPIOException("Can't write float value", ex);
@@ -1051,7 +1051,7 @@ protected void onFieldFloat(final Object obj, final Field field, final Bin annot
10511051
protected void onFieldString(final Object obj, final Field field, final Bin annotation, final String value) {
10521052
final JBBPByteOrder old = this.byteOrder;
10531053
try {
1054-
this.byteOrder = annotation.outByteOrder();
1054+
this.byteOrder = annotation.byteOrder();
10551055
this.String(value);
10561056
} catch (IOException ex) {
10571057
throw new JBBPIOException("Can't write string value", ex);
@@ -1064,7 +1064,7 @@ protected void onFieldString(final Object obj, final Field field, final Bin anno
10641064
protected void onFieldDouble(final Object obj, final Field field, final Bin annotation, final double value) {
10651065
final JBBPByteOrder old = this.byteOrder;
10661066
try {
1067-
this.byteOrder = annotation.outByteOrder();
1067+
this.byteOrder = annotation.byteOrder();
10681068
this.Double(value);
10691069
} catch (IOException ex) {
10701070
throw new JBBPIOException("Can't write double value", ex);
@@ -1077,7 +1077,7 @@ protected void onFieldDouble(final Object obj, final Field field, final Bin anno
10771077
protected void onFieldLong(final Object obj, final Field field, final Bin annotation, final long value) {
10781078
final JBBPByteOrder old = this.byteOrder;
10791079
try {
1080-
this.byteOrder = annotation.outByteOrder();
1080+
this.byteOrder = annotation.byteOrder();
10811081
this.Long(value);
10821082
} catch (IOException ex) {
10831083
throw new JBBPIOException("Can't write long value", ex);
@@ -1090,7 +1090,7 @@ protected void onFieldLong(final Object obj, final Field field, final Bin annota
10901090
protected void onFieldInt(final Object obj, final Field field, final Bin annotation, final int value) {
10911091
final JBBPByteOrder old = this.byteOrder;
10921092
try {
1093-
this.byteOrder = annotation.outByteOrder();
1093+
this.byteOrder = annotation.byteOrder();
10941094
this.Int(value);
10951095
} catch (IOException ex) {
10961096
throw new JBBPIOException("Can't write int value", ex);
@@ -1103,7 +1103,7 @@ protected void onFieldInt(final Object obj, final Field field, final Bin annotat
11031103
protected void onFieldShort(final Object obj, final Field field, final Bin annotation, final boolean signed, final int value) {
11041104
final JBBPByteOrder old = this.byteOrder;
11051105
try {
1106-
this.byteOrder = annotation.outByteOrder();
1106+
this.byteOrder = annotation.byteOrder();
11071107
this.Short(value);
11081108
} catch (IOException ex) {
11091109
throw new JBBPIOException("Can't write short value", ex);

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.igormaznitsa.jbbp.io.JBBPCustomFieldWriter;
2323
import com.igormaznitsa.jbbp.io.JBBPOut;
2424
import com.igormaznitsa.jbbp.utils.JBBPTextWriter;
25-
2625
import java.lang.annotation.ElementType;
2726
import java.lang.annotation.Inherited;
2827
import java.lang.annotation.Retention;
@@ -100,28 +99,28 @@
10099
* @see JBBPTextWriter#Bin(java.lang.Object...)
101100
* @see JBBPOut#Bin(java.lang.Object)
102101
* @see JBBPOut#Bin(java.lang.Object, com.igormaznitsa.jbbp.io.JBBPCustomFieldWriter)
103-
* @since 1.1
102+
* @since 2.0.0
104103
*/
105-
JBBPBitNumber outBitNumber() default JBBPBitNumber.BITS_8;
104+
JBBPBitNumber bitNumber() default JBBPBitNumber.BITS_8;
106105

107106
/**
108107
* Byte order to be used for write of the value.
109108
*
110109
* @return order of bytes to be used for field value write
111-
* @since 1.4.0
110+
* @since 2.0.0
112111
*/
113-
JBBPByteOrder outByteOrder() default JBBPByteOrder.BIG_ENDIAN;
112+
JBBPByteOrder byteOrder() default JBBPByteOrder.BIG_ENDIAN;
114113

115114
/**
116-
* The Value defines the field order to sort fields of the class for save or logging.
115+
* The Value defines the field order to sort fields of the class for save or logging. If -1then it is undefined.
117116
*
118117
* @return the outOrder of the field as number (the mapping will make ascending sorting)
119118
* @see JBBPTextWriter#Bin(java.lang.Object...)
120119
* @see JBBPOut#Bin(java.lang.Object)
121120
* @see JBBPOut#Bin(java.lang.Object, com.igormaznitsa.jbbp.io.JBBPCustomFieldWriter)
122-
* @since 1.1
121+
* @since 2.0.0
123122
*/
124-
int outOrder() default 0;
123+
int order() default -1;
125124

126125
/**
127126
* Just either description of the field or some remark.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public final class MappedFieldRecord implements Comparable<MappedFieldRecord> {
179179
this.mappingClass = mappingClass;
180180
this.binAnnotation = binAnnotation;
181181

182-
this.mappedBitNumber = binAnnotation.outBitNumber();
182+
this.mappedBitNumber = binAnnotation.bitNumber();
183183

184184
if (binAnnotation.type() == BinType.UNDEFINED) {
185185
BinType thetype = BinType.findCompatible(mappingField.getType());
@@ -510,8 +510,8 @@ void apply(
510510

511511
@Override
512512
public int compareTo(final MappedFieldRecord o) {
513-
final int thisOrder = this.binAnnotation.outOrder();
514-
final int thatOrder = o.binAnnotation.outOrder();
513+
final int thisOrder = this.binAnnotation.order();
514+
final int thatOrder = o.binAnnotation.order();
515515

516516
final int result;
517517
if (thisOrder == thatOrder) {

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.igormaznitsa.jbbp.io.JBBPByteOrder;
66
import com.igormaznitsa.jbbp.mapper.Bin;
77
import com.igormaznitsa.jbbp.mapper.BinType;
8-
98
import java.lang.reflect.Field;
109
import java.lang.reflect.Modifier;
1110
import java.util.ArrayList;
@@ -2050,9 +2049,9 @@ private int getOrder() {
20502049
return this.binCustom.order();
20512050
}
20522051
if (this.bin != null) {
2053-
return this.bin.outOrder();
2052+
return this.bin.order();
20542053
}
2055-
return 0;
2054+
return -1;
20562055
}
20572056

20582057
@Override
@@ -2110,7 +2109,7 @@ void addBinCustomField(final DslBinCustom bin, final boolean fieldLocalAnnotatio
21102109
}
21112110

21122111
JBBPByteOrder getByteOrder(final BinField field) {
2113-
return field.binCustom == null ? field.bin.outByteOrder() : field.binCustom.byteOrder();
2112+
return field.binCustom == null ? field.bin.byteOrder() : field.binCustom.byteOrder();
21142113
}
21152114

21162115
String getName() {
@@ -2121,10 +2120,10 @@ String getName() {
21212120
JBBPBitNumber getBitNumber(final BinField field) {
21222121
assertNotCustomBin();
21232122
final JBBPBitNumber result;
2124-
if (field.bin.outBitNumber() == JBBPBitNumber.BITS_8) {
2125-
result = this.bin == null ? JBBPBitNumber.BITS_8 : this.bin.outBitNumber();
2123+
if (field.bin.bitNumber() == JBBPBitNumber.BITS_8) {
2124+
result = this.bin == null ? JBBPBitNumber.BITS_8 : this.bin.bitNumber();
21262125
} else {
2127-
result = field.bin.outBitNumber();
2126+
result = field.bin.bitNumber();
21282127
}
21292128
return result;
21302129
}

0 commit comments

Comments
 (0)