44import org .agrona .generation .OutputManager ;
55import uk .co .real_logic .sbe .PrimitiveType ;
66import uk .co .real_logic .sbe .generation .CodeGenerator ;
7+ import uk .co .real_logic .sbe .generation .NamedToken ;
78import uk .co .real_logic .sbe .ir .*;
89
910import java .io .IOException ;
@@ -218,11 +219,9 @@ private static void generateMessageEncoder(
218219 final String messageTypeName = formatTypeName (msgToken .name ());
219220 final RustCodecType codecType = RustCodecType .Encoder ;
220221 String topType = codecType .generateDoneCoderType (outputManager , messageTypeName );
221- topType = generateTopVarDataCoders (messageTypeName , components .varData ,
222- outputManager , topType , codecType );
222+ topType = generateTopVarDataCoders (messageTypeName , components .varData , outputManager , topType , codecType );
223223 topType = generateGroupsCoders (groupTree , outputManager , topType , codecType );
224- topType = generateFixedFieldCoder (messageTypeName , outputManager , topType ,
225- fieldsRepresentation , codecType );
224+ topType = generateFixedFieldCoder (messageTypeName , outputManager , topType , fieldsRepresentation , codecType );
226225 topType = codecType .generateMessageHeaderCoder (messageTypeName , outputManager , topType , headerSize );
227226 generateEntryPoint (messageTypeName , outputManager , topType , codecType );
228227 }
@@ -240,11 +239,9 @@ private static void generateMessageDecoder(
240239 final String messageTypeName = formatTypeName (msgToken .name ());
241240 final RustCodecType codecType = RustCodecType .Decoder ;
242241 String topType = codecType .generateDoneCoderType (outputManager , messageTypeName );
243- topType = generateTopVarDataCoders (messageTypeName , components .varData ,
244- outputManager , topType , codecType );
242+ topType = generateTopVarDataCoders (messageTypeName , components .varData , outputManager , topType , codecType );
245243 topType = generateGroupsCoders (groupTree , outputManager , topType , codecType );
246- topType = generateFixedFieldCoder (messageTypeName , outputManager , topType ,
247- fieldsRepresentation , codecType );
244+ topType = generateFixedFieldCoder (messageTypeName , outputManager , topType , fieldsRepresentation , codecType );
248245 topType = codecType .generateMessageHeaderCoder (messageTypeName , outputManager , topType , headerSize );
249246 generateEntryPoint (messageTypeName , outputManager , topType , codecType );
250247 }
@@ -363,8 +360,14 @@ private static String generateGroupNodeEncoders(
363360 atEndOfCurrentLevel = false ;
364361 }
365362
366- return writeGroupEncoderTopTypes (outputManager , afterGroupCoderType , node , atEndOfParent ,
367- atEndOfCurrentLevel , memberCoderType , nextCoderType );
363+ return writeGroupEncoderTopTypes (
364+ outputManager ,
365+ afterGroupCoderType ,
366+ node ,
367+ atEndOfParent ,
368+ atEndOfCurrentLevel ,
369+ memberCoderType ,
370+ nextCoderType );
368371 }
369372
370373 private static String generateGroupNodeDecoders (
@@ -709,22 +712,21 @@ private static String toScratchChain(final int depth)
709712
710713 private static <T > Iterable <T > reversedList (final List <T > list )
711714 {
712- return () ->
713- {
714- if (list .isEmpty ())
715+ return
716+ () ->
715717 {
716- return list .stream ().iterator ();
717- }
718+ if (list .isEmpty ())
719+ {
720+ return list .stream ().iterator ();
721+ }
718722
719- final int maxIndex = list .size () - 1 ;
723+ final int maxIndex = list .size () - 1 ;
720724
721- return IntStream .rangeClosed (0 , maxIndex ).mapToObj ((i ) -> list .get (maxIndex - i )).iterator ();
722- };
725+ return IntStream .rangeClosed (0 , maxIndex ).mapToObj ((i ) -> list .get (maxIndex - i )).iterator ();
726+ };
723727 }
724728
725- private static List <GroupTreeNode > buildGroupTrees (
726- final String parentTypeName ,
727- final List <Token > groupsTokens )
729+ private static List <GroupTreeNode > buildGroupTrees (final String parentTypeName , final List <Token > groupsTokens )
728730 {
729731 return buildGroupTrees (parentTypeName , groupsTokens , Optional .empty ());
730732 }
@@ -971,13 +973,15 @@ String generateVarDataDecoder(
971973 {
972974 goToNext = format ("%s::wrap(self.%s)" , nextDecoderType , contentPropertyName );
973975 }
976+
974977 indent (writer , 2 ,
975978 "Ok((%s.read_slice::<%s>(count as usize, %s)?, %s))\n " , toScratchChain (groupDepth ),
976979 rustTypeName (this .dataType ), this .dataType .size (), goToNext );
977980 indent (writer ).append ("}\n " );
978981
979982 writer .append ("}\n " );
980983 }
984+
981985 return decoderType ;
982986 }
983987
@@ -1000,6 +1004,7 @@ static List<VarDataSummary> gatherVarDataSummaries(final List<Token> tokens)
10001004 summaries .add (new VarDataSummary (beginToken .name (), lengthType , dataType ));
10011005 i += headerTokenCount ;
10021006 }
1007+
10031008 return summaries ;
10041009 }
10051010 }
@@ -1008,8 +1013,9 @@ static String generateTopVarDataCoders(
10081013 final String messageTypeName ,
10091014 final List <Token > tokens ,
10101015 final OutputManager outputManager ,
1011- final String initialNextType , final RustCodecType codecType ) throws
1012- IOException
1016+ final String initialNextType ,
1017+ final RustCodecType codecType )
1018+ throws IOException
10131019 {
10141020 final List <VarDataSummary > summaries = VarDataSummary .gatherVarDataSummaries (tokens );
10151021
@@ -1051,16 +1057,19 @@ private static void generateEnums(final Ir ir, final OutputManager outputManager
10511057 {
10521058 continue ;
10531059 }
1060+
10541061 final Token beginToken = tokens .get (0 );
10551062 if (beginToken .signal () != BEGIN_ENUM )
10561063 {
10571064 continue ;
10581065 }
1066+
10591067 final String typeName = beginToken .applicableTypeName ();
10601068 if (enumTypeNames .contains (typeName ))
10611069 {
10621070 continue ;
10631071 }
1072+
10641073 generateEnum (tokens , outputManager );
10651074 enumTypeNames .add (typeName );
10661075 }
@@ -1297,8 +1306,8 @@ private static void generateComposites(final Ir ir, final OutputManager outputMa
12971306 }
12981307 }
12991308
1300- private static void generateSingleComposite (final List <Token > tokens , final OutputManager outputManager ) throws
1301- IOException
1309+ private static void generateSingleComposite (final List <Token > tokens , final OutputManager outputManager )
1310+ throws IOException
13021311 {
13031312 final Token beginToken = tokens .get (0 );
13041313 final String originalTypeName = beginToken .applicableTypeName ();
@@ -1307,7 +1316,7 @@ private static void generateSingleComposite(final List<Token> tokens, final Outp
13071316 try (Writer writer = outputManager .createOutput (formattedTypeName ))
13081317 {
13091318 appendStructHeader (writer , formattedTypeName , true );
1310- appendStructFields (writer , splitTokens .nonConstantEncodingTokens );
1319+ appendStructFields (writer , splitTokens .nonConstantEncodingTokens () );
13111320 writer .append ("}\n " );
13121321
13131322 generateConstantAccessorImpl (writer , formattedTypeName , getMessageBody (tokens ));
@@ -1319,13 +1328,13 @@ private static void appendStructFields(final Appendable appendable, final List<N
13191328 {
13201329 for (final NamedToken namedToken : namedTokens )
13211330 {
1322- final Token typeToken = namedToken .typeToken ;
1331+ final Token typeToken = namedToken .typeToken () ;
13231332 if (typeToken .isConstantEncoding ())
13241333 {
13251334 continue ;
13261335 }
13271336
1328- final String propertyName = formatMethodName (namedToken .name );
1337+ final String propertyName = formatMethodName (namedToken .name () );
13291338 indent (appendable ).append ("pub " ).append (propertyName ).append (":" );
13301339
13311340 switch (typeToken .signal ())
@@ -1387,14 +1396,14 @@ private void generateMessageHeaderDefault(
13871396 "version" ));
13881397
13891398 final List <NamedToken > nonReservedNamedTokens = SplitCompositeTokens .splitInnerTokens (header .tokens ())
1390- .nonConstantEncodingTokens
1399+ .nonConstantEncodingTokens ()
13911400 .stream ()
1392- .filter ((namedToken ) -> !reserved .contains (namedToken .name ))
1401+ .filter ((namedToken ) -> !reserved .contains (namedToken .name () ))
13931402 .collect (Collectors .toList ());
13941403
13951404 for (final NamedToken namedToken : nonReservedNamedTokens )
13961405 {
1397- indent (writer , 4 , "%s: Default::default(),\n " , formatMethodName (namedToken .name ));
1406+ indent (writer , 4 , "%s: Default::default(),\n " , formatMethodName (namedToken .name () ));
13981407 }
13991408
14001409 indent (writer , 3 , "}\n " );
@@ -1517,8 +1526,7 @@ private static void generateConstantAccessorImpl(
15171526 case BEGIN_SET :
15181527 case BEGIN_COMPOSITE :
15191528 default :
1520- throw new IllegalStateException (format ("Unsupported constant presence property " +
1521- "%s" , fieldToken .toString ()));
1529+ throw new IllegalStateException ("Unsupported constant presence property " + fieldToken );
15221530 }
15231531
15241532 appendConstAccessor (writer , name , constantRustTypeName , constantRustExpression );
0 commit comments