scovich commented on issue #7700:
URL: https://github.com/apache/arrow-rs/issues/7700#issuecomment-2989688229
The change looks great!
> The string length check right before appending also seems unavoidable
because it's possible for users to construct `Variant::ShortString` directly,
without doing input validation.
Good catch. That is indeed rather annoying. I guess we could potentially
mask off all but the lowest 6 bits of the string's length and write that. Then
the behavior is always well-defined?
```rust
fn append_short_string(&mut self, value: &str) {
let value = value[..value.len() & 0x3f];
self.buffer.push(short_string_header(value.len()));
self.buffer.extend_from_slice(value.as_bytes());
}
```
... except that could truncate the bytes in the middle of a utf8 sequence,
producing an invalid output. Ugh.
Alternatively, we could make `Variant` be a struct whose only (private)
field is today's enum? That way, we could enforce always-valid `Variant` values
via `try_new`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]