pub fn encode_field_name(field_name: &str) -> XRPLCoreResult<Vec<u8>>
Expand description
Returns the unique field ID for a given field name. This field ID consists of the type code and field code, in 1 to 3 bytes depending on whether those values are “common” (<16) or “uncommon” (>=16)
See Field Ids:
<https://xrpl.org/serialization.html#field-ids>
§Examples
§Basic usage
use xrpl::core::binarycodec::utils::encode_field_name;
use xrpl::core::binarycodec::exceptions::XRPLBinaryCodecException;
use xrpl::core::exceptions::XRPLCoreException;
extern crate alloc;
use alloc::vec;
let field_name: &str = "LedgerSequence";
let bytes: Vec<u8> = vec![38];
let encoding: Option<Vec<u8>> = match encode_field_name(field_name) {
Ok(bytes) => Some(bytes),
Err(e) => match e {
XRPLCoreException::XRPLBinaryCodecError(XRPLBinaryCodecException::UnknownFieldName) => None,
_ => None,
}
};
assert_eq!(Some(bytes), encoding);