Disable log messages

70 views
Skip to first unread message

snoriman

unread,
Nov 7, 2024, 9:53:07 AM11/7/24
to Protocol Buffers
Maybe a silly question, but I'm using `ParseFromArray()` and when the input data is missing some required fields I get a mesage like "Can't parase message of type <type> because it is missing required fields".

It still parses the message which is fine as I don't need the required data, however how can I I disable the output?


Em Rauch

unread,
Nov 7, 2024, 10:00:19 AM11/7/24
to Protocol Buffers
I think the function `ParsePartialFromArray()` is what you're looking for.

Note that generally you shouldn't rely on this too heavily though; if you serialize such a message and send it to another end point they will be expecting all required fields to be set and may correctly parse fail; the intent of ParsePartial is that if you're going to serialize it back out you should set the required fields first.

Broadly, required fields were removed from proto3 because they cause a lot of problems, including that they very hard to remove a required field when you realize you don't need it; eg you may think `string username` is required today but when you realize you want a `int64 userid` instead it's very hard to make that transition if you marked username as required. You may want to consider migrating your fields off of being marked required as a long term solution.

snoriman

unread,
Nov 7, 2024, 10:35:54 AM11/7/24
to Protocol Buffers
Thanks for you quick reply Em!  I'm going to read up on `ParsePartialFromArray()`. I'm not in control of the data stream and/or .proto files, merely integrating a SDK, but good to know about this!

Op donderdag 7 november 2024 om 16:00:19 UTC+1 schreef Em Rauch:
Reply all
Reply to author
Forward
0 new messages