diff --git a/README.md b/README.md index d9cac9a..e5c8264 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# AVRO codec (2.2.0) +# AVRO codec (2.2.1) ## Description Designed for decode AVRO raw messages to parsed messages and encode back. It is based on [th2-codec](https://github.com/th2-net/th2-codec). @@ -80,6 +80,9 @@ Only one of settings `sessionAliasToDictionaryAlias` or `avroMessageIdToDictiona ## Release notes +### 2.2.1 +* Added detailed TRACE logging for parsing into class com.exactpro.th2.codec.MessageDatumReader + ### 2.2.0 + Added mode resolution schema by session alias + Added support wildcard for session alias setting diff --git a/gradle.properties b/gradle.properties index b81ef23..8e4a655 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -release_version=2.2.0 +release_version=2.2.1 \ No newline at end of file diff --git a/src/main/kotlin/com/exactpro/th2/codec/MessageDatumReader.kt b/src/main/kotlin/com/exactpro/th2/codec/MessageDatumReader.kt index b159612..5501249 100644 --- a/src/main/kotlin/com/exactpro/th2/codec/MessageDatumReader.kt +++ b/src/main/kotlin/com/exactpro/th2/codec/MessageDatumReader.kt @@ -21,6 +21,7 @@ import com.exactpro.th2.common.grpc.Message import com.exactpro.th2.common.grpc.Value import com.exactpro.th2.common.message.addField import com.exactpro.th2.common.value.toValue +import com.google.protobuf.TextFormat.shortDebugString import org.apache.avro.* import org.apache.avro.data.TimeConversions.* import org.apache.avro.generic.* @@ -30,6 +31,7 @@ import java.io.IOException import java.nio.ByteBuffer import java.util.* import javax.xml.bind.DatatypeConverter +import mu.KotlinLogging class MessageDatumReader(schema: Schema, private val enableIdPrefixEnumFields: Boolean = false) : GenericDatumReader(schema, schema, getData()) { @@ -57,7 +59,6 @@ class MessageDatumReader(schema: Schema, private val enableIdPrefixEnumFields: B override fun readField(r: Any, f: Schema.Field, oldDatum: Any?, decoder: ResolvingDecoder, state: Any?) { var readValue = read(oldDatum, f.schema(), decoder) var fieldName = f.name() - if (readValue is UnionData) { val description = readValue.description readValue = readValue.value @@ -66,7 +67,9 @@ class MessageDatumReader(schema: Schema, private val enableIdPrefixEnumFields: B } } if (readValue != null) { - (r as Message.Builder).addField(fieldName, readValue.convertToValue()) + val convertedValue = readValue.convertToValue() + LOGGER.trace { "Read value ${f.name()}: ${shortDebugString(convertedValue)} (origin: $readValue)" } + (r as Message.Builder).addField(fieldName, convertedValue) } } @@ -98,6 +101,18 @@ class MessageDatumReader(schema: Schema, private val enableIdPrefixEnumFields: B return Message.newBuilder() } + override fun convert(datum: Any?, schema: Schema?, type: LogicalType?, conversion: Conversion<*>?): Any { + val convertedValue = super.convert(datum, schema, type, conversion) + if(LOGGER.isTraceEnabled) { + val rawValueString = when(datum) { + is ByteBuffer -> datum.asHexString() + else -> datum.toString() + } + LOGGER.trace { "Converting value using logical type ${type?.name} from $rawValueString to $convertedValue" } + } + return convertedValue + } + private fun ByteBuffer.asHexString(): String { val bytes = ByteArray(this.remaining()) this.get(bytes) @@ -116,6 +131,7 @@ class MessageDatumReader(schema: Schema, private val enableIdPrefixEnumFields: B val description: String ) companion object { + private val LOGGER = KotlinLogging.logger { } fun getData(): GenericData? { return GenericData.get().apply { addLogicalTypeConversion(Conversions.DecimalConversion())