padding.c 731 B

1234567891011121314151617181920212223242526272829303132
  1. #include <pb_encode.h>
  2. #include <unittests.h>
  3. #include <string.h>
  4. #include "padding.pb.h"
  5. int main()
  6. {
  7. int status = 0;
  8. TestMessage msg;
  9. /* Set padding bytes to garbage */
  10. memset(&msg, 0xAA, sizeof(msg));
  11. /* Set all meaningful fields to 0 */
  12. msg.submsg.boolfield = false;
  13. msg.submsg.intfield = 0;
  14. /* Test encoding */
  15. {
  16. pb_byte_t buf[128] = {0};
  17. pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf));
  18. TEST(pb_encode(&stream, TestMessage_fields, &msg));
  19. /* Because all fields have zero values, proto3 encoder
  20. * shouldn't write out anything. */
  21. TEST(stream.bytes_written == 0);
  22. }
  23. return status;
  24. }