Add countenvelope encoder with marshal/unmarshal support, buffer pool integration, and tests; improve error messages for subscription validation

This commit is contained in:
2025-08-30 16:26:55 +01:00
parent 6c39ea4332
commit 576475e3dc
8 changed files with 353 additions and 13 deletions

View File

@@ -87,7 +87,6 @@ func (en *T) Unmarshal(b []byte) (r []byte, err error) {
if en.Subscription, r, err = text.UnmarshalQuoted(r); chk.E(err) {
return
}
if r, err = text.Comma(r); chk.E(err) {
return
}

View File

@@ -7,14 +7,13 @@ import (
"next.orly.dev/pkg/encoders/envelopes"
"next.orly.dev/pkg/encoders/filter"
"next.orly.dev/pkg/utils"
"next.orly.dev/pkg/utils/bufpool"
)
func TestMarshalUnmarshal(t *testing.T) {
var err error
rb, rb1, rb2 := make([]byte, 0, 65535), make([]byte, 0, 65535), make(
[]byte, 0, 65535,
)
for i := range 1000 {
rb, rb1, rb2 := bufpool.Get(), bufpool.Get(), bufpool.Get()
var f filter.S
if f, err = filter.GenFilters(); chk.E(err) {
t.Fatal(err)
@@ -22,8 +21,7 @@ func TestMarshalUnmarshal(t *testing.T) {
s := utils.NewSubscription(i)
req := NewFrom(s, f)
rb = req.Marshal(rb)
rb1 = rb1[:len(rb)]
copy(rb1, rb)
rb1 = append(rb1, rb...)
var rem []byte
var l string
if l, rb, err = envelopes.Identify(rb); chk.E(err) {
@@ -64,6 +62,8 @@ func TestMarshalUnmarshal(t *testing.T) {
len(rb1), rb1, len(rb2), rb2,
)
}
rb, rb1, rb2 = rb[:0], rb1[:0], rb2[:0]
bufpool.Put(rb1)
bufpool.Put(rb2)
bufpool.Put(rb)
}
}