C++ Logo

std-proposals

Advanced search

Re: Modern std::byte stream IO for C++

From: Lyberta <lyberta_at_[hidden]>
Date: Fri, 6 Mar 2020 15:01:05 +0300
Maciej Cencora:
> Even if compilers will optimize the code out, all users will have the pay
> the cost of slower compilation (because compiler still needs to instantiate
> the serialization code for big/little endian).
> Basically with current design this is an early pessimization.

I will look into it when std::bit_cast and modules land. Only with those features in place we could get both compile time and
run time benchmarks that are fair.

> You should focus on providing low-level primitives first.
> Maybe something like Codec concept that allows serializing primitive types
> (instead of enum format member in context concept), and provide two
> implementations BigEndianCodec, LittleEndianCodec - and allow users to
> provide custom ones.

I would argue that primitive types + traits classes are violations of type system. I wanted to provide minimum default for the
most basic case and then let users write strong types that do their own serialization.

> With your current design I see no easy way to provide custom serialization
> codec (e.g. Type-Length-Value).

Just have a class template with custom serialization and wrap fundamental types in it. This is what I do for MIDI variable
length values and WebAssembly integers.


Received on 2020-03-06 06:03:59