pub enum BpsvFieldType {
String(u32),
Hex(u32),
Decimal(u32),
}Expand description
Represents a BPSV field type with its length specification
Variants§
String(u32)
String field with maximum length (0 = unlimited)
Hex(u32)
Hexadecimal field with byte count (N bytes = N*2 hex characters)
Decimal(u32)
Decimal number field with storage size in bytes (e.g., 4 = uint32)
Implementations§
Source§impl BpsvFieldType
impl BpsvFieldType
Sourcepub fn parse(type_spec: &str) -> Result<Self>
pub fn parse(type_spec: &str) -> Result<Self>
Parse a field type from a string like “STRING:0”, “HEX:16”, “DEC:4”
Parsing is case-insensitive for the type name.
§Examples
use ngdp_bpsv::BpsvFieldType;
assert_eq!(BpsvFieldType::parse("STRING:0")?, BpsvFieldType::String(0));
assert_eq!(BpsvFieldType::parse("string:0")?, BpsvFieldType::String(0));
assert_eq!(BpsvFieldType::parse("String:0")?, BpsvFieldType::String(0));
assert_eq!(BpsvFieldType::parse("HEX:16")?, BpsvFieldType::Hex(16));
assert_eq!(BpsvFieldType::parse("hex:16")?, BpsvFieldType::Hex(16));
assert_eq!(BpsvFieldType::parse("DEC:4")?, BpsvFieldType::Decimal(4));
assert_eq!(BpsvFieldType::parse("dec:4")?, BpsvFieldType::Decimal(4));Sourcepub fn is_valid_value(&self, value: &str) -> bool
pub fn is_valid_value(&self, value: &str) -> bool
Check if a string value is valid for this field type
§Examples
use ngdp_bpsv::BpsvFieldType;
let string_type = BpsvFieldType::String(5);
assert!(string_type.is_valid_value("hello"));
assert!(!string_type.is_valid_value("too_long")); // > 5 chars
let hex_type = BpsvFieldType::Hex(4); // 4 bytes = 8 hex chars
assert!(hex_type.is_valid_value("abcd1234"));
assert!(hex_type.is_valid_value("12345678"));
assert!(!hex_type.is_valid_value("xyz")); // invalid hex
assert!(!hex_type.is_valid_value("1234")); // wrong length (need 8 chars)
let dec_type = BpsvFieldType::Decimal(4);
assert!(dec_type.is_valid_value("1234"));
assert!(dec_type.is_valid_value("0"));
assert!(!dec_type.is_valid_value("abc")); // not a numberSourcepub fn validate_value(&self, value: &str) -> Result<String>
pub fn validate_value(&self, value: &str) -> Result<String>
Validate and potentially normalize a value for this field type
Returns the normalized value or an error if invalid.
Trait Implementations§
Source§impl Clone for BpsvFieldType
impl Clone for BpsvFieldType
Source§fn clone(&self) -> BpsvFieldType
fn clone(&self) -> BpsvFieldType
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BpsvFieldType
impl Debug for BpsvFieldType
Source§impl Display for BpsvFieldType
impl Display for BpsvFieldType
Source§impl Hash for BpsvFieldType
impl Hash for BpsvFieldType
Source§impl PartialEq for BpsvFieldType
impl PartialEq for BpsvFieldType
impl Eq for BpsvFieldType
impl StructuralPartialEq for BpsvFieldType
Auto Trait Implementations§
impl Freeze for BpsvFieldType
impl RefUnwindSafe for BpsvFieldType
impl Send for BpsvFieldType
impl Sync for BpsvFieldType
impl Unpin for BpsvFieldType
impl UnwindSafe for BpsvFieldType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more