Skip to content
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

Makes the Ion 1.1 text writer write symbol tokens inline by default, instead of using symbol identifiers. #1012

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 @@ -26,7 +26,7 @@ public static _Private_IonTextWriterBuilder_1_1 standard() {
return new _Private_IonTextWriterBuilder_1_1.Mutable();
}

private SymbolInliningStrategy symbolInliningStrategy = SymbolInliningStrategy.NEVER_INLINE;
private SymbolInliningStrategy symbolInliningStrategy = SymbolInliningStrategy.ALWAYS_INLINE;

private _Private_IonTextWriterBuilder_1_1() {
super();
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/com/amazon/ion/impl/bin/ManagedWriterOptions_1_1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,6 @@ data class ManagedWriterOptions_1_1(
val lengthPrefixStrategy: LengthPrefixStrategy,
val eExpressionIdentifierStrategy: EExpressionIdentifierStrategy,
) : SymbolInliningStrategy by symbolInliningStrategy, LengthPrefixStrategy by lengthPrefixStrategy {
companion object {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were unused. The defaults are now contained in the writer builders.

@JvmField
val ION_BINARY_DEFAULT = ManagedWriterOptions_1_1(
internEncodingDirectiveSymbols = true,
invokeTdlMacrosByName = false,
symbolInliningStrategy = SymbolInliningStrategy.NEVER_INLINE,
lengthPrefixStrategy = LengthPrefixStrategy.ALWAYS_PREFIXED,
eExpressionIdentifierStrategy = EExpressionIdentifierStrategy.BY_ADDRESS,
)
@JvmField
val ION_TEXT_DEFAULT = ManagedWriterOptions_1_1(
// Encoding directives are easier to read if we don't intern their keywords.
internEncodingDirectiveSymbols = false,
invokeTdlMacrosByName = true,
symbolInliningStrategy = SymbolInliningStrategy.ALWAYS_INLINE,
// This doesn't actually have any effect for Ion Text since there are no length-prefixed containers.
lengthPrefixStrategy = LengthPrefixStrategy.NEVER_PREFIXED,
eExpressionIdentifierStrategy = EExpressionIdentifierStrategy.BY_NAME,
)
}

/**
* Indicates whether e-expressions should be written using macro
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.amazon.ion.MacroAwareIonWriter;
import com.amazon.ion.SystemSymbols;
import com.amazon.ion.impl.bin.IonRawBinaryWriter_1_1;
import com.amazon.ion.impl.bin.SymbolInliningStrategy;
import com.amazon.ion.impl.macro.EncodingContext;
import com.amazon.ion.impl.macro.Expression;
import com.amazon.ion.impl.macro.Macro;
Expand Down Expand Up @@ -1606,7 +1607,42 @@ public void macroInvocationsProduceEncodingDirectivesThatModifySymbolTableMacroA
substringCount(SystemSymbols_1_1.ADD_MACROS, 0),
substringCount(SystemSymbols_1_1.SET_SYMBOLS, 2),
substringCount(SystemSymbols_1_1.SET_MACROS, 0),
substringCount(DEFAULT_MODULE_DIRECTIVE_PREFIX, 0)
substringCount(DEFAULT_MODULE_DIRECTIVE_PREFIX, 0),
// Symbol tokens are written using inline text, not symbol identifiers.
substringCount("$1", 0),
substringCount("$2", 0),
substringCount("$3", 0)
);
}

@ParameterizedTest(name = "{0},{1},{2}")
@MethodSource("allInputFormatsInputTypesAndOutputFormats")
public void macroInvocationsProduceEncodingDirectivesThatModifySymbolTableMacroAwareTranscodeWithoutInlining(
InputType inputType,
StreamType inputFormat,
StreamType outputFormat
) throws Exception {
byte[] data = macroInvocationsProduceEncodingDirectivesThatModifySymbolTable(inputFormat);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (
MacroAwareIonReader reader = inputType.newMacroAwareReader(data);
MacroAwareIonWriter rewriter = (MacroAwareIonWriter) (outputFormat == StreamType.TEXT
? IonEncodingVersion.ION_1_1.textWriterBuilder().withSymbolInliningStrategy(SymbolInliningStrategy.NEVER_INLINE).build(out)
: IonEncodingVersion.ION_1_1.binaryWriterBuilder().withSymbolInliningStrategy(SymbolInliningStrategy.NEVER_INLINE).build(out))
) {
reader.transcodeAllTo(rewriter);
}
verifyStream(data, out, outputFormat,
substringCount("$ion_1_1", 1),
substringCount(SystemSymbols_1_1.ADD_SYMBOLS, 1),
substringCount(SystemSymbols_1_1.ADD_MACROS, 0),
substringCount(SystemSymbols_1_1.SET_SYMBOLS, 2),
substringCount(SystemSymbols_1_1.SET_MACROS, 0),
substringCount(DEFAULT_MODULE_DIRECTIVE_PREFIX, 0),
// Symbol tokens are written using symbol identifiers, not inline text.
substringCount("$1", 3),
substringCount("$2", 2),
substringCount("$3", 1)
);
}

Expand Down
Loading