Skip to content

Commit

Permalink
[Validation] switch from a runtime property to determine whether to a…
Browse files Browse the repository at this point in the history
…pply empty tag validation to a codec build-time property. note: no mechanism for setting this build-time property has been added yet.
  • Loading branch information
writeoncereadmany committed Nov 30, 2023
1 parent 7f7e3c2 commit d465cbb
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 69 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.agrona.generation.PackageOutputManager;


import uk.co.real_logic.artio.builder.RejectEmptyTag;
import uk.co.real_logic.artio.builder.RejectUnknownEnumValue;
import uk.co.real_logic.artio.builder.RejectUnknownField;
import uk.co.real_logic.artio.builder.Validation;
Expand Down Expand Up @@ -166,7 +165,6 @@ private static void generateDictionary(
parentPackage,
encoderOutput,
Validation.class,
RejectEmptyTag.class,
RejectUnknownField.class,
RejectUnknownEnumValue.class,
codecRejectUnknownEnumValueEnabled,
Expand All @@ -180,11 +178,11 @@ private static void generateDictionary(
encoderPackage,
decoderOutput,
Validation.class,
RejectEmptyTag.class,
RejectUnknownField.class,
RejectUnknownEnumValue.class,
false,
configuration.wrapEmptyBuffer(),
false,
codecRejectUnknownEnumValueEnabled,
configuration.fixTagsInJavadoc()).generate();

Expand All @@ -203,11 +201,11 @@ private static void generateDictionary(
parentPackage,
encoderPackage, flyweightDecoderOutput,
Validation.class,
RejectEmptyTag.class,
RejectUnknownField.class,
RejectUnknownEnumValue.class,
true,
configuration.wrapEmptyBuffer(),
false,
codecRejectUnknownEnumValueEnabled,
configuration.fixTagsInJavadoc()).generate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class DecoderGenerator extends Generator
public static final int TAG_APPEARS_MORE_THAN_ONCE =
RejectReason.TAG_APPEARS_MORE_THAN_ONCE.representation();
public static final int TAG_SPECIFIED_OUT_OF_REQUIRED_ORDER = 14;
private final boolean allowEmptyTags;

static String decoderClassName(final Aggregate aggregate)
{
Expand All @@ -128,20 +129,21 @@ static String decoderClassName(final String name)
final String encoderPackage,
final OutputManager outputManager,
final Class<?> validationClass,
final Class<?> rejectEmptyTagClass,
final Class<?> rejectUnknownFieldClass,
final Class<?> rejectUnknownEnumValueClass,
final boolean flyweightsEnabled,
final boolean wrapEmptyBuffer,
final boolean allowEmptyTags,
final String codecRejectUnknownEnumValueEnabled,
final boolean fixTagsInJavadoc)
{
super(dictionary, thisPackage, commonPackage, outputManager, validationClass, rejectEmptyTagClass,
super(dictionary, thisPackage, commonPackage, outputManager, validationClass,
rejectUnknownFieldClass, rejectUnknownEnumValueClass, flyweightsEnabled, codecRejectUnknownEnumValueEnabled,
fixTagsInJavadoc);
this.initialBufferSize = initialBufferSize;
this.encoderPackage = encoderPackage;
this.wrapEmptyBuffer = wrapEmptyBuffer;
this.allowEmptyTags = allowEmptyTags;
}

public void generate()
Expand Down Expand Up @@ -1759,11 +1761,12 @@ private String generateDecodePrefix(
" invalidTagId = tag;\n" +
" rejectReason = " + INVALID_TAG_NUMBER + ";\n" +
" }\n" +
" else if (" + CODEC_REJECT_EMPTY_TAG_ENABLED + " && valueLength == 0)\n" +
(allowEmptyTags ? "" :
" else if (valueLength == 0)\n" +
" {\n" +
" invalidTagId = tag;\n" +
" rejectReason = " + TAG_SPECIFIED_WITHOUT_A_VALUE + ";\n" +
" }\n" +
" }\n") +
headerValidation(isHeader) +
(isGroup ? "" :
" if (!alreadyVisitedFields.add(tag))\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,12 @@ static String encoderClassName(final String name)
final String builderCommonPackage,
final OutputManager outputManager,
final Class<?> validationClass,
final Class<?> rejectEmptyTagClass,
final Class<?> rejectUnknownFieldClass,
final Class<?> rejectUnknownEnumValueClass,
final String codecRejectUnknownEnumValueEnabled,
final boolean fixTagsInJavadoc)
{
super(dictionary, builderPackage, builderCommonPackage, outputManager, validationClass, rejectEmptyTagClass,
super(dictionary, builderPackage, builderCommonPackage, outputManager, validationClass,
rejectUnknownFieldClass, rejectUnknownEnumValueClass, false, codecRejectUnknownEnumValueEnabled,
fixTagsInJavadoc);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ protected String commonCompoundImports(final String form, final boolean headerWr
private final String commonPackage;
protected final OutputManager outputManager;
protected final Class<?> validationClass;
protected final Class<?> rejectEmptyTagClass;
protected final Class<?> rejectUnknownFieldClass;
private final Class<?> rejectUnknownEnumValueClass;
protected final boolean flyweightsEnabled;
Expand All @@ -109,7 +108,6 @@ protected Generator(
final String commonPackage,
final OutputManager outputManager,
final Class<?> validationClass,
final Class<?> rejectEmptyTagClass,
final Class<?> rejectUnknownFieldClass,
final Class<?> rejectUnknownEnumValueClass,
final boolean flyweightsEnabled,
Expand All @@ -121,7 +119,6 @@ protected Generator(
this.commonPackage = commonPackage;
this.outputManager = outputManager;
this.validationClass = validationClass;
this.rejectEmptyTagClass = rejectEmptyTagClass;
this.rejectUnknownFieldClass = rejectUnknownFieldClass;
this.rejectUnknownEnumValueClass = rejectUnknownEnumValueClass;
this.flyweightsEnabled = flyweightsEnabled;
Expand Down Expand Up @@ -183,7 +180,6 @@ protected void generateImports(

out .append(importStaticFor(StandardCharsets.class, "US_ASCII"))
.append(importStaticFor(validationClass, CODEC_VALIDATION_ENABLED))
.append(importStaticFor(rejectEmptyTagClass, CODEC_REJECT_EMPTY_TAG_ENABLED))
.append(importStaticFor(rejectUnknownFieldClass, CODEC_REJECT_UNKNOWN_FIELD_ENABLED))
.append(importStaticFor(rejectUnknownEnumValueClass, RUNTIME_REJECT_UNKNOWN_ENUM_VALUE_PROPERTY));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ private static Map<String, CharSequence> generateSources(
)
{
final Class<?> validationClass = validation ? ValidationOn.class : ValidationOff.class;
final Class<?> rejectEmptyTag = rejectingEmptyTags ? RejectEmptyTagOn.class : RejectEmptyTagOff.class;
final Class<?> rejectUnknownField = rejectingUnknownFields ?
RejectUnknownFieldOn.class : RejectUnknownFieldOff.class;
final Class<?> rejectUnknownEnumValue = rejectingUnknownEnumValue ?
Expand All @@ -139,11 +138,11 @@ private static Map<String, CharSequence> generateSources(
final EnumGenerator enumGenerator = new EnumGenerator(MESSAGE_EXAMPLE, TEST_PARENT_PACKAGE, outputManager);
final DecoderGenerator decoderGenerator = new DecoderGenerator(
MESSAGE_EXAMPLE, 1, TEST_PACKAGE, TEST_PARENT_PACKAGE, TEST_PACKAGE,
outputManager, validationClass, rejectEmptyTag, rejectUnknownField,
rejectUnknownEnumValue, flyweightStringsEnabled, wrapEmptyBuffer,
outputManager, validationClass, rejectUnknownField,
rejectUnknownEnumValue, flyweightStringsEnabled, wrapEmptyBuffer, !rejectingEmptyTags,
String.valueOf(rejectingUnknownEnumValue), true);
final EncoderGenerator encoderGenerator = new EncoderGenerator(MESSAGE_EXAMPLE, TEST_PACKAGE,
TEST_PARENT_PACKAGE, outputManager, ValidationOn.class, RejectEmptyTagOn.class, RejectUnknownFieldOn.class,
TEST_PARENT_PACKAGE, outputManager, ValidationOn.class, RejectUnknownFieldOn.class,
RejectUnknownEnumValueOn.class, RUNTIME_REJECT_UNKNOWN_ENUM_VALUE_PROPERTY, true);

constantGenerator.generate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public class AcceptorGeneratorTest
private static final EnumGenerator ENUM_GENERATOR = new EnumGenerator(
MESSAGE_EXAMPLE, TEST_PACKAGE, OUTPUT_MANAGER);
private static final EncoderGenerator ENCODER_GENERATOR = new EncoderGenerator(
MESSAGE_EXAMPLE, TEST_PACKAGE, TEST_PARENT_PACKAGE, OUTPUT_MANAGER, ValidationOn.class, RejectEmptyTagOn.class,
MESSAGE_EXAMPLE, TEST_PACKAGE, TEST_PARENT_PACKAGE, OUTPUT_MANAGER, ValidationOn.class,
RejectUnknownFieldOn.class, RejectUnknownEnumValueOn.class, RUNTIME_REJECT_UNKNOWN_ENUM_VALUE_PROPERTY, true);
private static final DecoderGenerator DECODER_GENERATOR = new DecoderGenerator(
MESSAGE_EXAMPLE, 1, TEST_PACKAGE, TEST_PARENT_PACKAGE, TEST_PACKAGE, OUTPUT_MANAGER, ValidationOn.class,
RejectEmptyTagOn.class, RejectUnknownFieldOff.class, RejectUnknownEnumValueOn.class, false, false,
RejectUnknownFieldOff.class, RejectUnknownEnumValueOn.class, false, false, false,
Generator.RUNTIME_REJECT_UNKNOWN_ENUM_VALUE_PROPERTY, true);
private static final AcceptorGenerator ACCEPTOR_GENERATOR = new AcceptorGenerator(
MESSAGE_EXAMPLE, TEST_PACKAGE, OUTPUT_MANAGER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ private static Map<String, CharSequence> generateClasses()
final EnumGenerator enumGenerator = new EnumGenerator(MESSAGE_EXAMPLE, TEST_PARENT_PACKAGE, outputManager);
final DecoderGenerator decoderGenerator = new DecoderGenerator(
MESSAGE_EXAMPLE, 1, TEST_PACKAGE,
TEST_PARENT_PACKAGE, TEST_PACKAGE, outputManager, ValidationOn.class, RejectEmptyTagOn.class,
RejectUnknownFieldOn.class, RejectUnknownEnumValueOn.class, false, false,
TEST_PARENT_PACKAGE, TEST_PACKAGE, outputManager, ValidationOn.class,
RejectUnknownFieldOn.class, RejectUnknownEnumValueOn.class, false, false, false,
RUNTIME_REJECT_UNKNOWN_ENUM_VALUE_PROPERTY, true);
final EncoderGenerator encoderGenerator = new EncoderGenerator(MESSAGE_EXAMPLE, TEST_PACKAGE,
TEST_PARENT_PACKAGE, outputManager, ValidationOn.class, RejectEmptyTagOn.class, RejectUnknownFieldOn.class,
TEST_PARENT_PACKAGE, outputManager, ValidationOn.class, RejectUnknownFieldOn.class,
RejectUnknownEnumValueOn.class, RUNTIME_REJECT_UNKNOWN_ENUM_VALUE_PROPERTY, true);

constantGenerator.generate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,11 @@ private static Map<String, CharSequence> generateSources(final boolean validatio
final Class<?> validationClass = validation ? ValidationOn.class : ValidationOff.class;
final Class<?> rejectUnknownField = RejectUnknownFieldOff.class;
final Class<?> rejectUnknownEnumValue = RejectUnknownEnumValueOn.class;
final Class<?> rejectEmptyTag = RejectEmptyTagOn.class;
final StringWriterOutputManager outputManager = new StringWriterOutputManager();
final EnumGenerator enumGenerator = new EnumGenerator(MESSAGE_EXAMPLE, TEST_PARENT_PACKAGE, outputManager);
final EncoderGenerator encoderGenerator =
new EncoderGenerator(MESSAGE_EXAMPLE, TEST_PACKAGE, TEST_PARENT_PACKAGE, outputManager, validationClass,
rejectEmptyTag, rejectUnknownField, rejectUnknownEnumValue,
rejectUnknownField, rejectUnknownEnumValue,
Generator.RUNTIME_REJECT_UNKNOWN_ENUM_VALUE_PROPERTY, true);
enumGenerator.generate();
encoderGenerator.generate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public class PrinterGeneratorTest

private static final DecoderGenerator DECODER_GENERATOR = new DecoderGenerator(
MESSAGE_EXAMPLE, 1, TEST_PACKAGE, TEST_PARENT_PACKAGE, TEST_PACKAGE,
OUTPUT_MANAGER, ValidationOn.class, RejectEmptyTagOn.class,
RejectUnknownFieldOff.class, RejectUnknownEnumValueOn.class, false, false,
OUTPUT_MANAGER, ValidationOn.class,
RejectUnknownFieldOff.class, RejectUnknownEnumValueOn.class, false, false, false,
Generator.RUNTIME_REJECT_UNKNOWN_ENUM_VALUE_PROPERTY, true);
private static final EncoderGenerator ENCODER_GENERATOR = new EncoderGenerator(
MESSAGE_EXAMPLE, TEST_PACKAGE, TEST_PARENT_PACKAGE, OUTPUT_MANAGER, ValidationOn.class, RejectEmptyTagOn.class,
MESSAGE_EXAMPLE, TEST_PACKAGE, TEST_PARENT_PACKAGE, OUTPUT_MANAGER, ValidationOn.class,
RejectUnknownFieldOn.class, RejectUnknownEnumValueOn.class, RUNTIME_REJECT_UNKNOWN_ENUM_VALUE_PROPERTY,
true);

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ private static Map<String, CharSequence> generateClasses(final boolean flyweight
final EnumGenerator enumGenerator = new EnumGenerator(MESSAGE_EXAMPLE, TEST_PARENT_PACKAGE, outputManager);
final DecoderGenerator decoderGenerator = new DecoderGenerator(
MESSAGE_EXAMPLE, 1, TEST_PACKAGE,
TEST_PARENT_PACKAGE, TEST_PACKAGE, outputManager, ValidationOn.class, RejectEmptyTagOn.class,
RejectUnknownFieldOn.class, RejectUnknownEnumValueOn.class, flyweightStringsEnabled, false,
TEST_PARENT_PACKAGE, TEST_PACKAGE, outputManager, ValidationOn.class,
RejectUnknownFieldOn.class, RejectUnknownEnumValueOn.class, flyweightStringsEnabled, false, false,
RUNTIME_REJECT_UNKNOWN_ENUM_VALUE_PROPERTY, true);
final EncoderGenerator encoderGenerator = new EncoderGenerator(MESSAGE_EXAMPLE, TEST_PACKAGE,
TEST_PARENT_PACKAGE, outputManager, ValidationOn.class, RejectEmptyTagOn.class, RejectUnknownFieldOn.class,
TEST_PARENT_PACKAGE, outputManager, ValidationOn.class, RejectUnknownFieldOn.class,
RejectUnknownEnumValueOn.class, RUNTIME_REJECT_UNKNOWN_ENUM_VALUE_PROPERTY, true);

constantGenerator.generate();
Expand Down

0 comments on commit d465cbb

Please sign in to comment.