ingest: add wire format for incoming messages
This commit is contained in:
31
ingest/wire.go
Normal file
31
ingest/wire.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user