ingest: add wire format for incoming messages

This commit is contained in:
2025-04-06 08:57:04 -04:00
parent 8d6dbcb970
commit 844ad98142
9 changed files with 320 additions and 0 deletions

31
ingest/wire.go Normal file
View File

@@ -0,0 +1,31 @@
package ingest
import (
"fmt"
"io"
"github.com/go-json-experiment/json/jsontext"
)
// NullableString is a string that decodes JSON null as the empty string.
type NullableString string
func (n *NullableString) UnmarshalJSONFrom(d *jsontext.Decoder) error {
t, err := d.ReadToken()
switch err {
case nil: // do nothing
case io.EOF:
return io.ErrUnexpectedEOF
default:
return err
}
switch t.Kind() {
case 'n':
*n = ""
case '"':
*n = NullableString(t.String())
default:
return fmt.Errorf("invalid token for nullable string %q", t.String())
}
return nil
}