Skip to content

added maximum and minimum meta methods for allowed repeating group count #834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,15 @@ private void generateGroupEncoderClassHeader(
blockLengthType, blockLengthOffset, blockLengthValue, byteOrderString(blockLengthToken.encoding()));

final PrimitiveType numInGroupType = numInGroupToken.encoding().primitiveType();

final String javaTypeName = javaTypeName(numInGroupType);
final String minValue = generateLiteral(numInGroupType,
numInGroupToken.encoding().applicableMinValue().toString());
generatePrimitiveFieldMetaMethod(sb, ind, javaTypeName, "count", "Min", minValue);
final String maxValue = generateLiteral(numInGroupType,
numInGroupToken.encoding().applicableMaxValue().toString());
generatePrimitiveFieldMetaMethod(sb, ind, javaTypeName, "count", "Max", maxValue);

final PrimitiveType newInGroupTypeCast = PrimitiveType.UINT32 == numInGroupType ?
PrimitiveType.INT32 : numInGroupType;
final String numInGroupOffset = "limit + " + numInGroupToken.offset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,22 @@ public void shouldGeneratePutCharSequence() throws Exception
assertThat(get(decoder, "vehicleCode"), is("R11R12"));
}

@Test
public void shouldGenerateRepeatingGroupCountLimits() throws Exception
{
generator().generate();

final String className = "CarEncoder$FuelFiguresEncoder";
final String fqClassName = ir.applicableNamespace() + "." + className;

final Class<?> clazz = compile(fqClassName);
final Method minValue = clazz.getMethod("countMinValue");
assertNotNull(minValue);
assertEquals(0, minValue.invoke(null));
final Method maxValue = clazz.getMethod("countMaxValue");
assertNotNull(maxValue);
assertEquals(65534, maxValue.invoke(null));
}

private Class<?> getModelClass(final Object encoder) throws ClassNotFoundException
{
Expand Down