mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-07-07 14:49:56 +02:00
depressing sonic json decoder implementation, breakingly force COUNT to use a single filter, reorganize envelope tests.
This commit is contained in:
14
envelopes.go
14
envelopes.go
@ -164,7 +164,7 @@ func (v ReqEnvelope) MarshalJSON() ([]byte, error) {
|
||||
// CountEnvelope represents a COUNT message.
|
||||
type CountEnvelope struct {
|
||||
SubscriptionID string
|
||||
Filters
|
||||
Filter
|
||||
Count *int64
|
||||
HyperLogLog []byte
|
||||
}
|
||||
@ -198,12 +198,11 @@ func (v *CountEnvelope) UnmarshalJSON(data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
v.Filters = make(Filters, len(arr)-2)
|
||||
f := 0
|
||||
for i := 2; i < len(arr); i++ {
|
||||
item := []byte(arr[i].Raw)
|
||||
|
||||
if err := easyjson.Unmarshal(item, &v.Filters[f]); err != nil {
|
||||
if err := easyjson.Unmarshal(item, &v.Filter); err != nil {
|
||||
return fmt.Errorf("%w -- on filter %d", err, f)
|
||||
}
|
||||
|
||||
@ -217,9 +216,9 @@ func (v CountEnvelope) MarshalJSON() ([]byte, error) {
|
||||
w := jwriter.Writer{NoEscapeHTML: true}
|
||||
w.RawString(`["COUNT","`)
|
||||
w.RawString(v.SubscriptionID)
|
||||
w.RawString(`"`)
|
||||
w.RawString(`",`)
|
||||
if v.Count != nil {
|
||||
w.RawString(`,{"count":`)
|
||||
w.RawString(`{"count":`)
|
||||
w.RawString(strconv.FormatInt(*v.Count, 10))
|
||||
if v.HyperLogLog != nil {
|
||||
w.RawString(`,"hll":"`)
|
||||
@ -230,10 +229,7 @@ func (v CountEnvelope) MarshalJSON() ([]byte, error) {
|
||||
}
|
||||
w.RawString(`}`)
|
||||
} else {
|
||||
for _, filter := range v.Filters {
|
||||
w.RawString(`,`)
|
||||
filter.MarshalEasyJSON(&w)
|
||||
}
|
||||
v.Filter.MarshalEasyJSON(&w)
|
||||
}
|
||||
w.RawString(`]`)
|
||||
return w.BuildBytes()
|
||||
|
Reference in New Issue
Block a user