Problem with repeated bytes

15 views
Skip to first unread message

Alexis Lecoq

unread,
Feb 23, 2024, 10:20:05 AMFeb 23
to nanopb
Hi,

I'm having trouble with repeated bytes type.

I'm encoding the message from a c# app like this:

public Byte[] buildSetTidEpc(Dictionary<byte[], byte[]> tidEpcList)
{
    uDoorAPI api = new uDoorAPI();

    api.UdoorCmd = new udoorCmd();

    api.UdoorCmd.SetTidEpc = new SET_TID_EPC();

    foreach (byte[] t in tidEpcList.Keys)
    {
        api.UdoorCmd.SetTidEpc.TID.Add(ByteString.CopyFrom(t));
        api.UdoorCmd.SetTidEpc.EPC.Add(ByteString.CopyFrom(tidEpcList[t]));
    }

    return api.ToByteArray();
}

Then when sent to a mcu who's using nanopb I get an error. For every other messages type there's no problem decoding.

Here is the error:

[00:03:21.756,000] <dbg> tcpSocketsHandler: sock_thread: Rcv Len 286
[00:00:26.544,000] <dbg> tcpSocketsHandler: sock_thread: rcv cmd :
                                            12 9b 02 62 98 02 0a 0c  e2 80 11 70 20 00 12 12 |...b.... ...p ...
                                            e9 75 0a f5 0a 0c e2 80  11 70 20 00 14 56 20 71 |.u...... .p ..V q
                                            0a ef 0a 0c e2 80 11 70  20 00 04 8a 1d 6b 0a ef |.......p  ....k..
                                            0a 0c e2 80 11 70 20 00  10 0d 1c 78 0a ef 0a 0c |.....p . ...x....
                                            e2 80 11 70 20 00 03 a3  20 71 0a ef 0a 0c e2 80 |...p ...  q......
                                            11 70 20 00 13 70 1e c8  0a fe 0a 0c e2 80 11 70 |.p ..p.. .......p
                                            20 00 05 3f a6 82 0a a3  0a 0c e2 80 11 70 20 00 | ..?.... .....p .
                                            01 94 a7 0e 0a a3 0a 0c  e2 80 11 70 20 00 02 de |........ ...p ...
                                            19 45 0a fe 0a 0c e2 80  11 70 20 00 10 fc e4 f7 |.E...... .p .....
                                            0a f5 12 0c e2 80 11 70  20 00 00 00 00 00 00 1c |.......p  .......
                                            12 0c e2 80 11 70 20 00  00 00 00 00 00 6d 12 0c |.....p . .....m..
                                            e2 80 11 70 20 00 00 00  00 00 00 11 12 0c e2 80 |...p ... ........
                                            11 70 20 00 00 00 00 00  00 44 12 0c e2 80 11 70 |.p ..... .D.....p
                                            20 00 00 00 00 00 00 8f  12 0c e2 80 11 70 20 00 | ....... .....p .
                                            00 00 00 00 00 95 12 0c  e2 80 11 70 20 00 00 00 |........ ...p ...
                                            00 00 00 09 12 0c e2 80  11 70 20 00 00 00 00 00 |........ .p .....
                                            00 4e 12 0c e2 80 11 70  20 00 00 00 00 00 00 27 |.N.....p  ......'
                                            12 0c 62 e2 2d ad 7f 5f  3d 7f 0c 8c dc 52       |..b.-.._ =....R
[00:00:26.544,000] <err> cmd_interpretor: Decoding failed: parent stream too short

The packet seems good so I don't understand why it fails decoding it.


Petteri Aimonen

unread,
Feb 23, 2024, 10:57:56 AMFeb 23
to nanopb
Hi,

The protobuf data looks valid.

I would check:
  • That you are passing uDoorAPI_fields as argument to pb_decode()
  • That the length passed to pb_istream_from_buffer() is 286
  • That the .pb.h file is up to date and generated from the same .proto as the sending side.
If that doesn't help, please include the .proto file and I can take closer look.

--
Petteri

Alexis Lecoq

unread,
Feb 26, 2024, 4:06:33 AMFeb 26
to nanopb
Hi Petteri,

Sorry I've found the issue but couldn't find where to delete my post here. 

I was passing the rx buffer to a parsing function with the length in uint8 so 286 was overflowing it.

Thanks for helping !
Reply all
Reply to author
Forward
0 new messages