Add bitvec-like generic support to the scale-bits type for use in codegen (#718)

* Add bitvec-like generic support to the scale-bits type for use in codegen

* Use nightly 1.66 formatting

* Fix reading input while decoding bit sequences

* Add tests for our DecodedBits wrapper

* Add convenience DecodedBits::(in)to_bits functions

* Don't expose DecodedBits::bit_format

* Re-export scale_bits as peer dependency

* Move subxt::utils into a separate file

* Hide DecodedBits internals

* Don't re-export types from the `bits` module

* Update subxt/src/utils/bits.rs

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* Update subxt/src/utils/bits.rs

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* Address review feedback

* Clarify the byte needed calculation in DecodedBits encoding

* Remove remaining dbg! invocations

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
Igor Matuszewski
2022-11-24 15:09:20 +01:00
committed by GitHub
parent a80d6cfd30
commit f0ce26db7b
9 changed files with 273 additions and 28 deletions
+15 -3
View File
@@ -745,10 +745,22 @@ fn generate_bitvec() {
registry.register_type(&meta_type::<S>());
let portable_types: PortableRegistry = registry.into();
let substitutes = [
(
String::from("bitvec::order::Lsb0"),
parse_quote!(::subxt_path::utils::bits::Lsb0),
),
(
String::from("bitvec::order::Msb0"),
parse_quote!(::subxt_path::utils::bits::Msb0),
),
]
.into();
let type_gen = TypeGenerator::new(
&portable_types,
"root",
Default::default(),
substitutes,
DerivesRegistry::new(&"::subxt_path".into()),
"::subxt_path".into(),
);
@@ -762,8 +774,8 @@ fn generate_bitvec() {
use super::root;
#[derive(::subxt_path::ext::codec::Decode, ::subxt_path::ext::codec::Encode, Debug)]
pub struct S {
pub lsb: ::subxt_path::ext::bitvec::vec::BitVec<::core::primitive::u8, root::bitvec::order::Lsb0>,
pub msb: ::subxt_path::ext::bitvec::vec::BitVec<::core::primitive::u16, root::bitvec::order::Msb0>,
pub lsb: ::subxt_path::utils::bits::DecodedBits<::core::primitive::u8, ::subxt_path::utils::bits::Lsb0>,
pub msb: ::subxt_path::utils::bits::DecodedBits<::core::primitive::u16, ::subxt_path::utils::bits::Msb0>,
}
}
}
+1 -1
View File
@@ -246,7 +246,7 @@ impl TypePathType {
bit_store_type,
crate_path,
} => {
let type_path = parse_quote! { #crate_path::ext::bitvec::vec::BitVec<#bit_store_type, #bit_order_type> };
let type_path = parse_quote! { #crate_path::utils::bits::DecodedBits<#bit_store_type, #bit_order_type> };
syn::Type::Path(type_path)
}
}