vlm / asn1c

The ASN.1 Compiler
http://lionet.info/asn1c/
BSD 2-Clause "Simplified" License
1.03k stars 551 forks source link

uper_decode for packets over tcp stream #376

Open nnWhisperer opened 4 years ago

nnWhisperer commented 4 years ago

Hi, Thank you for the great work developing the project. I have generated uper_encode'd packets and am able to decode them correctly. Now, I am trying to send the packet buffer over a tcp stream, and having problems while decoding from the stream. As tcp is a stream protocol, some parts of the packet may arrive later, or may be appended with a part of other packet. How could we split the stream successfully into uper_decode'able packets? I am sure it is an already thought-out problem, however I have not been able to find an answer in the previous issues. Thank you,

velichkov commented 4 years ago

Hi @nnWhisperer,

How could we split the stream successfully into uper_decode'able packets?

From asn1c-usage.pdf.

4.2 Decoding BER

The decoder is restartable (stream-oriented). That means that in case the buffer has less data than expected, the decoder will process whatever is available and ask for more data to be provided using the RC_WMORE return .code. Note that in the RC_WMORE case the decoder may have processed less data than it is available in the buffer, which means that you must be able to arrange the next buffer to contain the unprocessed part of the previous buffer.

nnWhisperer commented 4 years ago

Hi @velichkov, I have actually read the manual, however I'm using per and uper is not restartable, as I had mentioned uper_encode keyword.

velichkov commented 4 years ago

Yes PER encodings are not restartable but the same technique is used for PER as well. Have a look at skeletons/converter-example.c