@@ -1164,16 +1164,45 @@ private CharSequence generateChoiceDecoders(final List<Token> tokens)
1164
1164
final Encoding encoding = token .encoding ();
1165
1165
final String choiceBitIndex = encoding .constValue ().toString ();
1166
1166
final String byteOrderStr = byteOrderString (encoding );
1167
+ final PrimitiveType primitiveType = encoding .primitiveType ();
1168
+ final String argType ;
1169
+
1170
+ switch (primitiveType )
1171
+ {
1172
+ case UINT8 :
1173
+ argType = "byte" ;
1174
+ break ;
1175
+
1176
+ case UINT16 :
1177
+ argType = "short" ;
1178
+ break ;
1179
+
1180
+ case UINT32 :
1181
+ argType = "int" ;
1182
+ break ;
1183
+
1184
+ case UINT64 :
1185
+ argType = "long" ;
1186
+ break ;
1187
+
1188
+ default :
1189
+ throw new IllegalStateException ("Invalid type: " + primitiveType );
1190
+ }
1167
1191
1168
1192
return String .format (
1169
1193
"\n " +
1170
- " public boolean %s()\n " +
1194
+ " public boolean %1$ s()\n " +
1171
1195
" {\n " +
1172
- " return %s;\n " +
1196
+ " return %2$s;\n " +
1197
+ " }\n \n " +
1198
+ " public static boolean %1$s(final %3$s value)\n " +
1199
+ " {\n " +
1200
+ " return %4$s;\n " +
1173
1201
" }\n " ,
1174
1202
choiceName ,
1175
- generateChoiceGet (encoding .primitiveType (), choiceBitIndex , byteOrderStr )
1176
- );
1203
+ generateChoiceGet (primitiveType , choiceBitIndex , byteOrderStr ),
1204
+ argType ,
1205
+ generateStaticChoiceGet (primitiveType , choiceBitIndex ));
1177
1206
});
1178
1207
}
1179
1208
@@ -2602,6 +2631,26 @@ private String generateChoiceGet(final PrimitiveType type, final String bitIndex
2602
2631
throw new IllegalArgumentException ("primitive type not supported: " + type );
2603
2632
}
2604
2633
2634
+ private String generateStaticChoiceGet (final PrimitiveType type , final String bitIndex )
2635
+ {
2636
+ switch (type )
2637
+ {
2638
+ case UINT8 :
2639
+ return "0 != (value & (1 << " + bitIndex + "))" ;
2640
+
2641
+ case UINT16 :
2642
+ return "0 != (value & (1 << " + bitIndex + "))" ;
2643
+
2644
+ case UINT32 :
2645
+ return "0 != (value & (1 << " + bitIndex + "))" ;
2646
+
2647
+ case UINT64 :
2648
+ return "0 != (value & (1L << " + bitIndex + "))" ;
2649
+ }
2650
+
2651
+ throw new IllegalArgumentException ("primitive type not supported: " + type );
2652
+ }
2653
+
2605
2654
private String generateChoicePut (
2606
2655
final PrimitiveType type , final String bitIdx , final String byteOrder )
2607
2656
{
0 commit comments