Skip to content

Commit

Permalink
Improves the factoring of the macro-aware transcoding tests and appli…
Browse files Browse the repository at this point in the history
…es minor cleanups.
  • Loading branch information
tgregg committed Nov 27, 2024
1 parent 7482237 commit 44da868
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1365,10 +1365,8 @@ private Event coreNextValue() {
/**
* Read an encoding directive. If the stream ends before the encoding directive finishes, `event` will be
* `NEEDS_DATA` and this method can be called again when more data is available.
* @param preserveMacroNames true if new macros should be referred to by name. If false, new macros will be
* referred to by integer ID.
*/
void readEncodingDirective(boolean preserveMacroNames) {
void readEncodingDirective() {
Event event;
while (true) {
switch (state) {
Expand Down Expand Up @@ -1502,7 +1500,7 @@ void readEncodingDirective(boolean preserveMacroNames) {
Macro newMacro = macroCompiler.compileMacro();
newMacros.put(MacroRef.byId(++localMacroMaxOffset), newMacro);
String macroName = macroCompiler.getMacroName();
if (preserveMacroNames && macroName != null) {
if (macroName != null) {
newMacros.put(MacroRef.byName(macroName), newMacro);
}
state = State.IN_MACRO_TABLE_SEXP;
Expand Down Expand Up @@ -1802,8 +1800,10 @@ private boolean evaluateNext() {

@Override
public void transcodeTo(MacroAwareIonWriter writer) throws IOException {
registerIvmNotificationConsumer((x, y) -> {
registerIvmNotificationConsumer((major, minor) -> {
resetEncodingContext();
// Which IVM to write is inherent to the writer implementation.
// We don't have a single implementation that writes both formats.
writer.startEncodingSegmentWithIonVersionMarker();
});
while (transcodeNextTo(writer) != Event.NEEDS_DATA);
Expand All @@ -1825,7 +1825,7 @@ Event transcodeNextTo(MacroAwareIonWriter writer) throws IOException {
if (parent == null || state != State.READING_VALUE) {
if (state != State.READING_VALUE && state != State.COMPILING_MACRO) {
boolean isEncodingDirectiveFromEExpression = isEvaluatingEExpression;
encodingDirectiveReader.readEncodingDirective(true);
encodingDirectiveReader.readEncodingDirective();
if (state != State.READING_VALUE) {
throw new IonException("Unexpected EOF when writing encoding-level value.");
}
Expand Down Expand Up @@ -1895,7 +1895,7 @@ public Event nextValue() {
while (true) {
if (parent == null || state != State.READING_VALUE) {
if (state != State.READING_VALUE && state != State.COMPILING_MACRO) {
encodingDirectiveReader.readEncodingDirective(false);
encodingDirectiveReader.readEncodingDirective();
if (state != State.READING_VALUE) {
event = Event.NEEDS_DATA;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ internal class IonReaderFromReaderAdapter(val reader: ReaderAdapter) : IonReader

override fun decimalValue(): Decimal = reader.ionDecimalValue()

override fun dateValue(): Date {
TODO("Not yet implemented")
}
override fun dateValue(): Date = TODO("Not yet implemented")

override fun doubleValue(): Double = reader.doubleValue()

Expand All @@ -47,25 +45,17 @@ internal class IonReaderFromReaderAdapter(val reader: ReaderAdapter) : IonReader

override fun getDepth(): Int = reader.getDepth()

override fun getSymbolTable(): SymbolTable {
TODO("Not yet implemented")
}
override fun getSymbolTable(): SymbolTable = TODO("Not yet implemented")

override fun getType(): IonType? = reader.encodingType()

override fun getTypeAnnotationSymbols(): Array<SymbolToken> = reader.getTypeAnnotationSymbols().toTypedArray()

override fun iterateTypeAnnotations(): MutableIterator<String> {
TODO("Not yet implemented")
}
override fun iterateTypeAnnotations(): MutableIterator<String> = TODO("Not yet implemented")

override fun getFieldId(): Int {
TODO("Not yet implemented")
}
override fun getFieldId(): Int = TODO("Not yet implemented")

override fun getFieldName(): String {
TODO("Not yet implemented")
}
override fun getFieldName(): String = TODO("Not yet implemented")

override fun booleanValue(): Boolean = reader.booleanValue()

Expand All @@ -79,21 +69,15 @@ internal class IonReaderFromReaderAdapter(val reader: ReaderAdapter) : IonReader

override fun newBytes(): ByteArray = reader.newBytes()

override fun getBytes(buffer: ByteArray?, offset: Int, len: Int): Int {
TODO("Not yet implemented")
}
override fun getBytes(buffer: ByteArray?, offset: Int, len: Int): Int = TODO("Not yet implemented")

override fun symbolValue(): SymbolToken = reader.symbolValue()

override fun byteSize(): Int {
TODO("Not yet implemented")
}
override fun byteSize(): Int = TODO("Not yet implemented")

override fun getIntegerSize(): IntegerSize = reader.getIntegerSize()

override fun getTypeAnnotations(): Array<String> {
TODO("Not yet implemented")
}
override fun getTypeAnnotations(): Array<String> = TODO("Not yet implemented")

override fun getFieldNameSymbol(): SymbolToken = reader.getFieldNameSymbol()

Expand Down
Loading

0 comments on commit 44da868

Please sign in to comment.