1 package codec
2 3 import (
4 "io"
5 )
6 7 type I interface {
8 MarshalWrite(w io.Writer) (err error)
9 UnmarshalRead(r io.Reader) (err error)
10 }
11 12 // Envelope is an interface for the nostr "envelope" message formats, a JSON
13 // array with the first field an upper case string that provides type
14 // information, in combination with the context of the side sending it (relay or
15 // client).
16 type Envelope interface {
17 // Label returns the (uppercase) string that signifies the type of message.
18 Label() string
19 // Write outputs the envelope to an io.Writer
20 Write(w io.Writer) (err error)
21 // JSON is a somewhat simplified version of the
22 // json.Marshaler/json.Unmarshaler that has no error for the Marshal side of
23 // the operation.
24 JSON
25 }
26 27 // JSON is a somewhat simplified version of the json.Marshaler/json.Unmarshaler
28 // that has no error for the Marshal side of the operation.
29 type JSON interface {
30 // Marshal converts the data of the type into JSON, appending it to the provided
31 // slice and returning the extended slice.
32 Marshal(dst []byte) (b []byte)
33 // Unmarshal decodes a JSON form of a type back into the runtime form, and
34 // returns whatever remains after the type has been decoded out.
35 Unmarshal(b []byte) (r []byte, err error)
36 }
37 38 // Binary is a similarly simplified form of the stdlib binary Marshal/Unmarshal
39 // server. Same as JSON it does not have an error for the MarshalBinary.
40 type Binary interface {
41 // MarshalBinary converts the data of the type into binary form, appending
42 // it to the provided slice.
43 MarshalBinary(dst []byte) (b []byte)
44 // UnmarshalBinary decodes a binary form of a type back into the runtime
45 // form, and returns whatever remains after the type has been decoded out.
46 UnmarshalBinary(b []byte) (r []byte, err error)
47 }
48