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

@@ -94,6 +94,18 @@ func (ev *E) Free() {
ev.b = nil
}
// EstimateSize returns a size for the event that allows for worst case scenario
// expansion of the escaped content and tags.
func (ev *E) EstimateSize() (size int) {
size = len(ev.ID)*2 + len(ev.Pubkey)*2 + len(ev.Sig)*2 + len(ev.Content)*2
for _, v := range *ev.Tags {
for _, w := range (*v).T {
size += len(w) * 2
}
}
return
}
func (ev *E) Marshal(dst []byte) (b []byte) {
b = dst
b = append(b, '{')