clockworklabs / SpacetimeDB

Multiplayer at the speed of light
https://spacetimedb.com
Other
4.41k stars 110 forks source link

`bsatn::from_slice` should return an error if it does not consume the whole slice #1942

Open bfops opened 2 weeks ago

bfops commented 2 weeks ago

There seems to be no bsatn validation

  • Add field to existing reducer type
  • Generate client code
  • Forget to publish updated server
  • Reducer still runs, but data is deserialized incorrectly I know proper versioning is difficult, but a check like "if we're done deserializing everything and there's still data in stream then throw error" would be nice

Unlike bsatn::from_reader, from_slice is only ever useful to read a single instance from a slice, as it does not return or signal where a caller would continue reading the next element. As such, from_slice should return an error if it does not read the slice to the end, as this most likely represents a type error. bsatn::from_reader should not change, as it remains useful to use that function to read multiple elements sequentially out of a single reader.