@@ -1165,29 +1165,7 @@ private CharSequence generateChoiceDecoders(final List<Token> tokens)
11651165 final String choiceBitIndex = encoding .constValue ().toString ();
11661166 final String byteOrderStr = byteOrderString (encoding );
11671167 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- }
1168+ final String argType = bitsetArgType (primitiveType );
11911169
11921170 return String .format (
11931171 "\n " +
@@ -1217,20 +1195,49 @@ private CharSequence generateChoiceEncoders(final String bitSetClassName, final
12171195 final Encoding encoding = token .encoding ();
12181196 final String choiceBitIndex = encoding .constValue ().toString ();
12191197 final String byteOrderStr = byteOrderString (encoding );
1198+ final PrimitiveType primitiveType = encoding .primitiveType ();
1199+ final String argType = bitsetArgType (primitiveType );
12201200
12211201 return String .format (
12221202 "\n " +
1223- " public %s %s(final boolean value)\n " +
1203+ " public %1$ s %2$ s(final boolean value)\n " +
12241204 " {\n " +
1225- "%s\n " +
1205+ "%3$ s\n " +
12261206 " return this;\n " +
1207+ " }\n \n " +
1208+ " public static %4$s %2$s(final %4$s bits, final boolean value)\n " +
1209+ " {\n " +
1210+ "%5$s" +
12271211 " }\n " ,
12281212 bitSetClassName ,
12291213 choiceName ,
1230- generateChoicePut (encoding .primitiveType (), choiceBitIndex , byteOrderStr ));
1214+ generateChoicePut (encoding .primitiveType (), choiceBitIndex , byteOrderStr ),
1215+ argType ,
1216+ generateStaticChoicePut (encoding .primitiveType (), choiceBitIndex ));
12311217 });
12321218 }
12331219
1220+ private String bitsetArgType (final PrimitiveType primitiveType )
1221+ {
1222+ switch (primitiveType )
1223+ {
1224+ case UINT8 :
1225+ return "byte" ;
1226+
1227+ case UINT16 :
1228+ return "short" ;
1229+
1230+ case UINT32 :
1231+ return "int" ;
1232+
1233+ case UINT64 :
1234+ return "long" ;
1235+
1236+ default :
1237+ throw new IllegalStateException ("Invalid type: " + primitiveType );
1238+ }
1239+ }
1240+
12341241 private CharSequence generateEnumValues (final List <Token > tokens )
12351242 {
12361243 final StringBuilder sb = new StringBuilder ();
@@ -2590,8 +2597,7 @@ private String generateStaticChoiceGet(final PrimitiveType type, final String bi
25902597 throw new IllegalArgumentException ("primitive type not supported: " + type );
25912598 }
25922599
2593- private String generateChoicePut (
2594- final PrimitiveType type , final String bitIdx , final String byteOrder )
2600+ private String generateChoicePut (final PrimitiveType type , final String bitIdx , final String byteOrder )
25952601 {
25962602 switch (type )
25972603 {
@@ -2623,6 +2629,30 @@ private String generateChoicePut(
26232629 throw new IllegalArgumentException ("primitive type not supported: " + type );
26242630 }
26252631
2632+ private String generateStaticChoicePut (final PrimitiveType type , final String bitIdx )
2633+ {
2634+ switch (type )
2635+ {
2636+ case UINT8 :
2637+ return
2638+ " return (byte)(value ? bits | (1 << " + bitIdx + ") : bits & ~(1 << " + bitIdx + "));\n " ;
2639+
2640+ case UINT16 :
2641+ return
2642+ " return (short)(value ? bits | (1 << " + bitIdx + ") : bits & ~(1 << " + bitIdx + "));\n " ;
2643+
2644+ case UINT32 :
2645+ return
2646+ " return value ? bits | (1 << " + bitIdx + ") : bits & ~(1 << " + bitIdx + ");\n " ;
2647+
2648+ case UINT64 :
2649+ return
2650+ " return value ? bits | (1L << " + bitIdx + ") : bits & ~(1L << " + bitIdx + ");\n " ;
2651+ }
2652+
2653+ throw new IllegalArgumentException ("primitive type not supported: " + type );
2654+ }
2655+
26262656 private CharSequence generateEncoderDisplay (final String decoderName , final String baseIndent )
26272657 {
26282658 final String indent = baseIndent + INDENT ;
0 commit comments