-
Notifications
You must be signed in to change notification settings - Fork 88
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
postcard-schema: nalgebra
schema is incorrect
#181
Comments
Hi, I don't recall exactly why I picked a |
So it turns out this is very frustrating to fix, this is what I've come up with: #[cfg_attr(docsrs, doc(cfg(feature = "nalgebra-v0_33")))]
impl<T, const R: usize, const C: usize> Schema
for nalgebra_v0_33::Matrix<
T,
nalgebra_v0_33::Const<R>,
nalgebra_v0_33::Const<C>,
nalgebra_v0_33::ArrayStorage<T, R, C>,
>
where
T: Schema + nalgebra_v0_33::Scalar,
{
/// Warning! This is not TECHNICALLY correct. nalgebra actually serializes the
/// ArrayStorage as `[T; R * C]`, however there is no way to express this below,
/// as we cannot use generics from the outer context in const context to do
/// what we really want here, which is `<[T; R * C]>::SCHEMA.ty`. For the
/// purposes of postcard, these two are actually equivalent with respect to
/// size and other meaning, but crates like `postcard-dyn` may make this
/// difference visible, and give the user the nested arrays instead of the
/// flat array.
const SCHEMA: &'static NamedType = &NamedType {
name: "nalgebra::Matrix<T, R, C, ArrayStorage<T, R, C>>",
ty: <[[T; R]; C]>::SCHEMA.ty,
};
} This will need to be a breaking change to I definitely need to raise the bar for required testing to add schema types! Also no worries @avsaase, I made the same mistake with So many things to learn :) |
Hey @avsaase - I was wondering how you chose
Seq(T)
for the schema ofnalgebra::Matrix
. ASeq
is a length prefixed item, so a 3x3 matrix ofu8
s should be 10 bytes. However this test fails:Was the choice of
Seq(T)
a guess? Or were you basing this on something else? Just making sure I understand the original choice before I change it.It appears to me that the actual serialized form is actually
[u8; 9]
, which is not a length prefixed, but is actually modeled as a tuple of size N, which avoids serializing a fixed size len:The text was updated successfully, but these errors were encountered: