pub fn write_bytes<B, const ALIGN: usize, const SOL_MODE: bool>(
buf: &mut BytesMut,
offset: usize,
data: &[u8],
elements: u32,
) -> usizewhere
B: ByteOrder,Expand description
Universal function to write bytes in Solidity or WASM compatible format
§Parameters
buf: A mutable reference to aBytesMutbuffer where the bytes will be written.header_offset: The offset in the buffer where the header should be written.data: A slice of bytes representing the data to be written.elements: The number of elements in the dynamic array.
§Type Parameters
B: The byte order to be used (e.g.,BigEndianorLittleEndian).ALIGN: The alignment size.SOL_MODE: A boolean indicating whether to use Solidity mode (true) or WASM mode (false).
§Returns
The number of bytes written, including alignment.
§Example
use bytes::BytesMut;
use byteorder::BigEndian;
use fluentbase_codec::bytes_codec::write_bytes;
let mut buf = BytesMut::new();
let data = &[1, 2, 3, 4, 5];
let elements = data.len() as u32;
let written = write_bytes::<BigEndian, 32, true>(&mut buf, 0, data, elements);
assert_eq!(written, 37);