Skip to content

Add emit_binary() to serialize::Encoder trait #12293

Closed
@mneumann

Description

@mneumann

My proposal is to extend trait serialize::Encoder with:

pub trait Encoder {
    fn emit_binary(&mut self, bin: &[u8]);
}

Which special cases emit_seq for u8's. Msgpack for example support both binaries and sequences of values, while sequences of values incur more overhead because it needs to encode the elements type for each element.

Right now it is not possible to efficiently emit binary type, like type bin = ~[u8] using the Encoder trait. With this change it would be possible. Orthogonally a read_binary() should be added to the Decoder trait, but it is not that important, as read_seq can be overloaded accordingly to read both binaries or sequences.

The default behaviour of emit_binary() could be made to emit a sequence, so almost no code need to be changed.

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