Each builder supports different and frequently differently named methods for appending. It should be possible to establish a more consistent convention, which would alleviate dev confusion and simplify generics.
For example, let all Builders be required to define at minimum:
- a nested type named Scalar, which is the canonical scalar appended to this builder. Append other types may be supported for convenience.
The other methods described below can be overridden if an optimization is available or left defaulted (a CRTP helper can contain the default implementations, for example Append(Scalar) would simply be a call to Reserve then UnsafeAppend.
In addition to their unsafe equivalents, Append(Scalar) and AppendNull() should be available for appending without manual capacity maintenance.
It is not necessary for the rest of this RFC, but it would simplify builders further if scalar append methods always had a single argument. For example, this would mean abolishing BinaryBuilder::Append(const uint8_t*, int32_t) in favor of BinaryBuilder::Append(basic_string_view<uint8_t>). There's no runtime overhead involved in this change, and developers who have a pointer and a length instead of a view can just construct one without boilerplate using brace initialization:
Unsafe and safe methods should be provided for appending multiple values as well. The default implementation will be a trivial loop but if optimizations are available then this could be overridden (for example instead of copying bits one by one into a BooleanBuilder, bytes could be memcpy'd). Append methods for multiple values should accept two arguments, the first of which contains values and the second of which defines validity. The canonical multiple append method has signature Status(array_view<Scalar> values, const uint8_t* valid_bytes), but other overloads and helpers could be provided as well:
Builders of nested types currently require developers to write boilerplate wrangling the child builders. This could be alleviated by letting nested builders' append methods return a helper as an output argument: