Skip to main content

encode_custom_attribute_argument

Function encode_custom_attribute_argument 

pub fn encode_custom_attribute_argument(
    arg: &CustomAttributeArgument,
    buffer: &mut Vec<u8>,
) -> Result<()>
Expand description

Encodes a single custom attribute argument value into binary format.

This function handles all supported .NET types according to the ECMA-335 specification, using the appropriate binary encoding for each type variant.

§Arguments

  • arg - The argument to encode
  • buffer - The output buffer to write encoded data to

§Type Encoding

Each type is encoded according to its specific format:

  • Primitives: Little-endian binary representation
  • Strings: Compressed length + UTF-8 data (or 0xFF for null)
  • Arrays: Compressed length + encoded elements
  • Enums: Underlying type value (type name encoded separately in named args)

§Errors

Returns [crate::Error::Malformed] in the following cases:

  • Char: Character code point exceeds 0xFFFF (outside Basic Multilingual Plane)
  • String: String length exceeds compressed uint maximum (0x1FFFFFFF bytes)
  • Array: Array length exceeds u32 maximum (4,294,967,295 elements)
  • Recursive errors from nested array element encoding