Add eventenvelope codec with support for Submission and Result envelopes, implement EstimateSize, and increase buffer capacity

This commit is contained in:
2025-08-30 14:43:32 +01:00
parent 431f37763d
commit faa527756b
5 changed files with 309 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ import (
"next.orly.dev/pkg/encoders/event"
text2 "next.orly.dev/pkg/encoders/text"
"next.orly.dev/pkg/interfaces/codec"
"next.orly.dev/pkg/utils/units"
)
// L is the label associated with this type of codec.Envelope.
@@ -194,6 +195,11 @@ func (en *Response) Marshal(dst []byte) (b []byte) {
err = errorf.E("nil event in response")
return
}
// if the destination capacity is not large enough, allocate a new
// destination slice.
if en.Event.EstimateSize() >= cap(dst) {
dst = make([]byte, 0, en.Event.EstimateSize()+units.Kb)
}
b = dst
b = envs.Marshal(b, L, en.Event.Marshal)
_ = err