Expand description
Scaled fixed-point conversion helpers used by the generated bitfields.
Every generated numeric field exposes the physical value as an f32
(the Rust equivalent of the C float the definitions use), while the
bitfield stores a raw N-bit integer. These const functions apply the
divisor / multiplier from the JSON formatter spec and, for signed
fields, sign-extend the stored bits.
They are referenced by the #[bits(N, from = .., into = ..)] attributes
that generate_all_messages! emits, e.g.
#[bits(12, from = conv::div_from_u16::<12, 10>, into = conv::div_into_u16::<12, 10>)].
Bis the field width in bits (used for masking / sign-extension only).ARGis the formatter argument (the divisor or multiplier).
Functions§
- div_
from_ u8 - unsigned, divide: physical = raw / ARG
- div_
from_ u16 - unsigned, divide: physical = raw / ARG
- div_
from_ u32 - unsigned, divide: physical = raw / ARG
- div_
from_ u64 - unsigned, divide: physical = raw / ARG
- div_
into_ u8 - The clamped result is always within the
#[bits(B)]range, sobitfield_struct’s bounds check never fires. This is why a custom try is needed - div_
into_ u16 - The clamped result is always within the
#[bits(B)]range, sobitfield_struct’s bounds check never fires. This is why a custom try is needed - div_
into_ u32 - The clamped result is always within the
#[bits(B)]range, sobitfield_struct’s bounds check never fires. This is why a custom try is needed - div_
into_ u64 - The clamped result is always within the
#[bits(B)]range, sobitfield_struct’s bounds check never fires. This is why a custom try is needed - mul_
from_ u8 - unsigned, multiply: physical = raw * ARG
- mul_
from_ u16 - unsigned, multiply: physical = raw * ARG
- mul_
from_ u32 - unsigned, multiply: physical = raw * ARG
- mul_
from_ u64 - unsigned, multiply: physical = raw * ARG
- mul_
into_ u8 - Saturates the raw count to
[0, 2^B - 1](see$div_into). - mul_
into_ u16 - Saturates the raw count to
[0, 2^B - 1](see$div_into). - mul_
into_ u32 - Saturates the raw count to
[0, 2^B - 1](see$div_into). - mul_
into_ u64 - Saturates the raw count to
[0, 2^B - 1](see$div_into). - sdiv_
from_ u8 - signed, divide: sign-extended over B bits on read.
- sdiv_
from_ u16 - signed, divide: sign-extended over B bits on read.
- sdiv_
from_ u32 - signed, divide: sign-extended over B bits on read.
- sdiv_
from_ u64 - signed, divide: sign-extended over B bits on read.
- sdiv_
into_ u8 - Saturates the raw count to
[-2^(B-1), 2^(B-1) - 1], then masks to B bits so the two’s-complement pattern fits the field. - sdiv_
into_ u16 - Saturates the raw count to
[-2^(B-1), 2^(B-1) - 1], then masks to B bits so the two’s-complement pattern fits the field. - sdiv_
into_ u32 - Saturates the raw count to
[-2^(B-1), 2^(B-1) - 1], then masks to B bits so the two’s-complement pattern fits the field. - sdiv_
into_ u64 - Saturates the raw count to
[-2^(B-1), 2^(B-1) - 1], then masks to B bits so the two’s-complement pattern fits the field. - smul_
from_ u8 - signed, multiply: sign-extended over B bits on read.
- smul_
from_ u16 - signed, multiply: sign-extended over B bits on read.
- smul_
from_ u32 - signed, multiply: sign-extended over B bits on read.
- smul_
from_ u64 - signed, multiply: sign-extended over B bits on read.
- smul_
into_ u8 - Saturates the raw count to
[-2^(B-1), 2^(B-1) - 1](see$sdiv_into). - smul_
into_ u16 - Saturates the raw count to
[-2^(B-1), 2^(B-1) - 1](see$sdiv_into). - smul_
into_ u32 - Saturates the raw count to
[-2^(B-1), 2^(B-1) - 1](see$sdiv_into). - smul_
into_ u64 - Saturates the raw count to
[-2^(B-1), 2^(B-1) - 1](see$sdiv_into).