Fix bug checking the length of binary types#263
Fix bug checking the length of binary types#263p32blo wants to merge 7 commits intoBergmann89:masterfrom
Conversation
Bergmann89
left a comment
There was a problem hiding this comment.
Hey @p32blo,
thanks for your contribution. The fix looks good in principle, but I’d
suggest a slightly different approach. Handling special constraints
directly in the generator shifts complexity to the wrong place. In my
opinion, it’s better to let the type itself handle this.
I would introduce the following types (in xsd-parser-types::xml):
pub struct HexString(pub String);
impl HexString {
/// Returns the byte length of the decoded data, and not the length of the string.
pub fn len(&self) -> usize { ... }
pub fn as_str(&self) -> &str { ... }
}
pub struct Base64String(pub String);
impl Base64String {
/// Returns the byte length of the decoded data, and not the length of the string.
pub fn len(&self) -> usize { ... }
pub fn as_str(&self) -> &str { ... }
}
pub struct HexBinary(pub Vec<u8>);
impl Deref for HexBinary { ... }
pub struct Base64Binary(pub Vec<u8>);
impl Deref for Base64Binary { ... }By default, HexString and Base64String would represent
xs:hexBinary and xs:base64Binary. This keeps compatibility with the
current string-based approach and avoids decoding unless necessary. If
a user needs the decoded form, they can switch to the binary types.
Providing suitable helpers in the config (see
Config::with_qname_type and Config::with_qname_type_from) would let
users choose the type they want.
This approach should not require changes to the interpreter or
generator, keeping the codebase cleaner while still solving the general
problem.
d4f8a57 to
32f1f3c
Compare
When we have a restriction on a binary type to check for its length, the size that needs to be considered is the octet size. So for a `xs:hexBinary` that might be represented by a string of 4 caracteres it actually only has length 2. The same for `xs:base64Binary` but the computation of the length is not as straight forward. Here is the relevant part of the standard: **lenght** https://www.w3.org/TR/xmlschema11-2/#rf-length **hexBinary** https://www.w3.org/TR/xmlschema11-2/#hexBinary **base64Binary** https://www.w3.org/TR/xmlschema11-2/#base64Binary
|
Thanks for the feedback. I tried to give it a go :) I was not able to figure out how to make the |
|
I think I addressed all the comments. I'm still not sure if it's the best way to handle the default values of |
When we have a restriction on a binary type to check for its length, the size that needs to be considered is the octet size.
So for a
xs:hexBinarythat might be represented by a string of 4 caracteres it actually only has length 2.The same for
xs:base64Binarybut the computation of the length is not as straight forward.Here is the relevant part of the standard:
lenght - https://www.w3.org/TR/xmlschema11-2/#rf-length
hexBinary - https://www.w3.org/TR/xmlschema11-2/#hexBinary
base64Binary - https://www.w3.org/TR/xmlschema11-2/#base64Binary
This is my attempt to fix this, but feel free to change it completely if it does not make sense to do it this way :)