I want to identify if the file to be deserialized is protobuf serialized. This is because I want to provide more than one option to serialize and deserialize the files for the user. I am using protobuf.net to serialize to protobuf format.
I want to identify if the file to be deserialized is protobuf serialized. This is because I want to provide more than one option to serialize and deserialize the files for the user. I am using protobuf.net to serialize to protobuf format.
There is no explicit protobuf marker that exists, so all you can do is test whether something could feasibly be protobuf. You could do that by trying to deserialize (and noting failure), or by simply running it through the ProtoReader API and seeing whether it runs cleanly to the end, perhaps using SkipField() (however, not that if you use SkipField(), there are some inner payloads that can be skipped completely - I could construct an example that passes when using SkipField(), but fails when deserialized properly).
Since you are using files, you could also use the file extension as an additional hint.