Hello, I have faced with problem on JS Browser tar...
# serialization
o
Hello, I have faced with problem on JS Browser target. It is very strange, but all serial formats can't decode data which were incoded by themself. The most strangest here that I have created tests which should represent this issue, but they was correctly passed. I have tried to encode bytearra with cbor. Serializer was
ListSerializer
with data class subserializer, which have one custom serializer in it. As a result on trying to decode encoded bytearray I got error like
Expected array, but found 00
. I have tried to find some known issue on github or in the google, but didn't find it. Maybe, somebody here faced this too and could help me?
n
can you provide minimal example that reproduces it ?
☝️ 2
o
I have tried to reproduce it with tests, but unsucessfull - all tests are passed when on practice it fails
a
I think I saw something similar. The problem is that JS sometimes does not make difference between single value arrays and objects. Can you try to use array explicitely?
o
I have used ListArray. I will try to use array serializer for that, but not sure that it will help
a
Just check the serialized form and see if it is correct.
I assume that the serializer is wrong, not deserializer.
o
Still got error on decoding:
Copy code
kotlinx.serialization.cbor.internal.CborDecodingException: Expected start of array, but found 00
        at kotlinx.serialization.cbor.internal.CborDecoder.startSized(Encoding.kt:320)
        at kotlinx.serialization.cbor.internal.CborDecoder.startArray(Encoding.kt:310)
        at kotlinx.serialization.cbor.internal.CborListReader.skipBeginToken(Encoding.kt:193)
        at kotlinx.serialization.cbor.internal.CborReader.beginStructure(Encoding.kt:227)
        at kotlinx.serialization.internal.AbstractCollectionSerializer.merge(CollectionSerializers.kt:29)
        at kotlinx.serialization.internal.AbstractCollectionSerializer.deserialize(CollectionSerializers.kt:43)
        at kotlinx.serialization.encoding.Decoder$DefaultImpls.decodeSerializableValue(Decoding.kt:243)
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:18)
        at kotlinx.serialization.cbor.internal.CborReader.decodeSerializableValue(Encoding.kt:250)
        at kotlinx.serialization.cbor.Cbor.decodeFromByteArray(Cbor.kt:51)
        at it is my code link.invokeSuspend(ServerRoutingShortcuts.kt:76)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(PipelineContext.kt:243)
        at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:199)
        at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:68)
        at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(PipelineContext.kt:149)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:834)
I have found that even empty body (body with empty array is empty on sent) have two leading zeros on the server side
a
I am not sure about cbor specification, but such a problem should be easy to isolate
o
Yes, currently I am trying to just skip first two zeros
About cbor: I have got previously almost the same problem with other serial formats
a
In Json it is quite easy to debug because you can just see the serialization output
o
That is current input on server side. I am pretty sure that request was sent correctly
Currently I am trying to use json serial format
For json it have worked correctly (or, at least, it looks like correct)
t
cbor.me can be used to help visualize CBOR data, might help with debugging.
o
Thank you