spxbhuhb / adaptive

Consolidated full-stack application development library for Kotlin
https://adaptive.fun
Apache License 2.0
3 stars 0 forks source link

[wireformat] ProtoWireFormatEncoder.subEncoder resets more than once with polymorphic encoding #67

Open toth-istvan-zoltan opened 2 months ago

toth-istvan-zoltan commented 2 months ago

I think the error is here, because instance is called in apply and the subencoder will be used by instance again.

 override fun <T> polymorphic(fieldNumber: Int, fieldName: String, value: T, wireFormat: WireFormat<T>): WireFormatEncoder {
        val bytes = subEncoder.apply {
            string(1, "", wireFormat.wireFormatName)
            instance(2, "", value, wireFormat)
        }.pack()
        writer.bytes(fieldNumber, bytes)
        return this
    }