by dotnetchris · 10y ago · 0 comments
What could go wrong
"We should just have used binary for everything!" - said every C/C++ developer ever.
"We should just have used Json for everything!" - said everyone currently.
Protobufs FTW.
2. Requires code generation. Not a big hassle especially if your IDE hides it, but a hassle nevertheless.
I've never understood the objection to code generation (or IDLs). If you actually care about what the serialized form looks like (and compatbility, etc.) this is by far the sanest way to do it.
It's also incredibly simple (i.e. transparent to inspection), it's a good way to do cross-platform/language marshalling.
You can get around the strict typing by adopting a schema format, but then you have a tooling problem that all the languages you need to support may not support your chosen JSON schema format.
Other solutions such as protobufs exist and are far better for transmitting large amounts of binary data.
Sharing c structs across languages is brave but it is doable as long as padding/offsets/lengths are expertly crafted and very strictly controlled.
but on the other hand sharing pointers would be madness.