Always encoding to zero bytes

17 views
Skip to first unread message

Eric Poulsen

unread,
May 16, 2025, 2:16:40 AMMay 16
to nanopb
I have a protocol that is proto2, all fields are required, all arrays are fixed length, with max_size

For some reason the encoded length is always zero, even when using PB_OSTREAM_SIZING.

No error is returned, and max_size is nonzero (and larger than the max encoded size) when not doing sizing.

Is there some edge case I'm missing?


Petteri Aimonen

unread,
May 16, 2025, 2:18:07 AMMay 16
to nan...@googlegroups.com
Hi,

No, I don't know any edge case that should affect it.

Can you make an example code that reproduces the problem?

--
Petteri
> --
> You received this message because you are subscribed to the Google Groups "nanopb" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nanopb+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/nanopb/c7771d34-2a69-44c8-8b4b-2e54d47c3395n%40googlegroups.com.
> --
> You received this message because you are subscribed to the Google
> Groups "nanopb" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [1]nanopb+un...@googlegroups.com.
> To view this discussion visit
> [2]https://groups.google.com/d/msgid/nanopb/c7771d34-2a69-44c8-8b4b-2e5
> 4d47c3395n%40googlegroups.com.
>
> References
>
> 1. mailto:nanopb+un...@googlegroups.com
> 2. https://groups.google.com/d/msgid/nanopb/c7771d34-2a69-44c8...@googlegroups.com?utm_medium=email&utm_source=footer


Eric Poulsen

unread,
May 16, 2025, 7:42:05 PMMay 16
to nanopb
Short answer: In the process of making a test case, I found the issue.

Longer answer: Below, I pass in *dbg_pkt, which is already a pointer, and then proceed to use &dbg_pkt in the encode.


dbms_result_e dbms_client_debug_write(dbms_client_ctx_t *ctx, int tag, dbms_debug_cmd_packet_t *dbg_pkt) {
dbms_comm_packet_t comm_pkt;
bool ok;

dbg_pkt->which_cmds = tag;
fprintf(stderr, "debug tag is %02X\n", tag);

memset(&comm_pkt, 0xAA, sizeof(comm_pkt));
pb_ostream_t dbg_os = pb_ostream_from_buffer(&comm_pkt.regs.debug_info, sizeof(comm_pkt.regs.debug_info));
// pb_ostream_t dbg_os = PB_OSTREAM_SIZING;
fprintf(stderr, "max_size: %d\n", dbg_os.max_size);
ok = pb_encode_ex(&dbg_os, dbms_debug_cmd_packet_t_fields, &dbg_pkt, PB_ENCODE_DELIMITED);
// ok = pb_encode_ex(&dbg_os, dbms_debug_cmd_packet_t_fields, &dbg_pkt, 0);
fprintf(stderr, "bytes encoded: %d\n", dbg_os.bytes_written);
if (!ok) {
fprintf(stderr, "encode debug packet error: %s\n", PB_GET_ERROR(&dbg_os));
return DBMS_RESULT_PB_ERR;
}
return dbms_client_write_reg(ctx, DBMS_DEBUG_INFO, &comm_pkt);
Reply all
Reply to author
Forward
0 new messages