-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: add length_width
to schema::Definition::Sequence
#229
Conversation
Add Definition::Sequence::length_width field which allows specifying the width of the length tag for dynamically-sized arrays. This allows defining custom schema where length is, say, one-byte. Furthermore, support length_width being zero which indicates untagged sequences. Use that as a new way to describe a fixed-length arrays thus making Definition::Array no longer necessary. Lastly, zero length_width with length range which is more than just one value allows to document a custom encoding which cannot be fully specified with the schema.
Duplicate of #228 |
@@ -53,14 +66,15 @@ fn validate_impl<'a>( | |||
stack.push(declaration); | |||
match definition { | |||
Definition::Primitive(_size) => {} | |||
Definition::Array { elements, .. } => validate_impl(elements, schema, stack)?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thread 'validate_for_derived_types' panicked at 'assertion failed: `(left == right)`
left: `Ok(())`,
right: `Err(ZSTSequence("Array<nil, 300>"))`'
length_width
to schema::Definition::Sequence
/// only 0, 1, 2, 4 and 8 bytes long enum tags and sequences' `length_width` are alowed | ||
TagNotPowerOfTwo(Declaration), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, why?
// TODO(#230): variants.len() is actually incorrect here. Since | ||
// arbitrary discriminant can be used for variants, an actual | ||
// largest discriminant may be larger than the number of variants. | ||
// For the time being we’re using variants.len() as a proxy but | ||
// eventually variant discriminants should be added to the schema. | ||
let max_discriminant = variants.len().saturating_sub(1) as u64; | ||
check_tag_width(declaration, *tag_width, max_discriminant)?; | ||
if *tag_width > U64_LEN { | ||
return Err(Error::TagTooWide(declaration.to_string())); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So length_width: 3
is invalid (for whatever reason), but tag_width: 3
is valid?
Add Definition::Sequence::length_width field which allows specifying
the width of the length tag for dynamically-sized arrays. This allows
defining custom schema where length is, say, one-byte.
Furthermore, support length_width being zero which indicates untagged
sequences. Use that as a new way to describe a fixed-length arrays
thus making Definition::Array no longer necessary.
Lastly, zero length_width with length range which is more than just
one value allows to document a custom encoding which cannot be fully
specified with the schema.
resolves #211 (
VarInt
andSmallVec<T>
)