Using scale, an enum can be written like this:
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub enum Block {
#[codec(index = 101)]
V1(BlockV1),
}
The #[codec(index = 101)]
, the 101
part, represents the u8
value that will be encoded in the serialization to represent the current enum arm. When this enum gets serialized, the first byte of that serialization will have the value 101
.
Given that this whole mechanism is built-in into the scale-codec, and given that making assumptions about serialization is wrong to respect encapsulation, is there a way to retrieve that 101
through a method call to the enum?
So I'm hoping for something like:
fn make_block() -> Block {
// some implementation
}
fn get_that_version() -> u8 {
let block = make_block();
assert_eq!(block.codec_arm_index(), 101u8); // notice 101 is the same from the enum
block.codec_arm_index()
}
Is such functionality available in scale?