proposal: encoding: BinaryMarshaler should be an append API #24630
Labels
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Proposal
v2
A language change or incompatible library change
Milestone
The BinaryMarshaler API returns a freshly allocated byte slice. This makes it unadvisable to implement for high performance APIs, or even APIs that could happen to be used in high performance scenarios.
If it had an append-like API (
MarshalBinary([]byte) ([]byte, error)
) then also a lot of high performance and internal parsing operations could be BinaryMarshaler implementations, allowing more standard interface reuse.The usability is not much worse, as
nil
can be passed to get the exact same behavior, and there's precedent inhash.Hash.Sum
.The text was updated successfully, but these errors were encountered: