Skip to content
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

Bug: If top-level struct is registered, every field will be treated as registered #28

Open
liamsi opened this issue Apr 6, 2020 · 1 comment

Comments

@liamsi
Copy link
Contributor

liamsi commented Apr 6, 2020

The macro-generated code always checks the top-level attributes of the wrapping message for is_registered instead of on a per field basis :-/

We haven't noticed that so far because the only place this feature was (successfully) used was for PubKeyMsg which contains only one field which also happen to be registered.

if #is_registered {
// skip some bytes: varint(total_len) || prefix_bytes
// prefix (4) + total_encoded_len:
let _full_len = _prost::encoding::decode_varint(buf)?;
buf.advance(4);
}

let top_level_attrs: Vec<syn::Attribute> = input.attrs;
let amino_name_attrs: Vec<syn::Attribute> = top_level_attrs
.into_iter()
.filter(|a| a.path.segments.first().unwrap().value().ident == "amino_name")
.collect();
if amino_name_attrs.len() > 1 {
bail!("got more than one registered amino_name");
}
let is_registered = amino_name_attrs.len() == 1;

Additionally, this length computation is wrong:

if #is_registered {
// TODO: in go-amino this only get length-prefixed if MarhsalBinary is used
// opposed to MarshalBinaryBare
let len = 4 #(+ #encoded_len2)*;
_prost::encoding::encode_varint(len as u64, buf);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant