Add warning about improper JSON encoding with json.Marshal in event.E documentation and emphasize buffer pool usage.

This commit is contained in:
2025-08-23 02:35:15 +01:00
parent 0f7f3017ea
commit f15db4313b

View File

@@ -20,7 +20,13 @@ import (
// E is the primary datatype of nostr. This is the form of the structure that // E is the primary datatype of nostr. This is the form of the structure that
// defines its JSON string-based format. Always use New() and Free() to create // defines its JSON string-based format. Always use New() and Free() to create
// and free event.E. // and free event.E to take advantage of the bufpool which greatly improves
// memory allocation behaviour when encoding and decoding nostr events.
//
// WARNING: DO NOT use json.Marshal with this type because it will not properly
// encode <, >, and & characters due to legacy bullcrap in the encoding/json
// library. Either call MarshalJSON directly or use a json.Encoder with html
// escaping disabled.
type E struct { type E struct {
// ID is the SHA256 hash of the canonical encoding of the event in binary format // ID is the SHA256 hash of the canonical encoding of the event in binary format