Skip to content

Serialize into externally allocated buffer #35

@MathiasKoch

Description

@MathiasKoch

It would be nice to have the option of passing in a byte slice to be used in serialization, rather than the internal buffer.

Usecase example:

pub fn as_json(&self, buf: &mut [u8]) -> Result<usize, ()> {
    let json = serde_json_core::to_vec::<consts::U1024, _>(&self).map_err(|_e| ())?;
    let len = json.len();
    buf[..len].copy_from_slice(&json);
    Ok(len)
}

Would be awesome to be able to:

pub fn as_json(&self, buf: &mut [u8]) -> Result<usize, ()> {
    let len = serde_json_core::to_slice(&self, &buf).map_err(|_e| ())?;
    Ok(len)
}

Where to_slice would just populate buf[0..len] with the serialized output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions