package b1 import "encoding/binary" import "fmt" import "io" type B1onKind int64 const ( B1onObjectKind B1onKind = 'O' B1onArrayKind B1onKind = 'A' B1onStringKind B1onKind = 'S' B1onIntegerKind B1onKind = 'I' B1onDoubleKind B1onKind = 'D' B1onTrueKind B1onKind = 'T' B1onFalseKind B1onKind = 'F' B1onNullKind B1onKind = 'N' ) func (k B1onKind) MarshalBinary(w io.Writer) error { return binary.Write(w, binary.LittleEndian, k) } func (k *B1onKind) UnmarshalBinary(r io.Reader) error { return binary.Read(r, binary.LittleEndian, k) } type B1onValue interface { Kind() B1onKind MarshalBinary(io.Writer) error UnmarshalBinary(io.Writer) error JsonString() string } type B1onPair struct { Key string Value B1onValue } type B1onObject struct { Members []B1onPair } type B1onArray struct { Members []B1onValue } type B1onString string func (s B1onString) Kind() B1onKind { return B1onStringKind } func (s B1onString) MarshalBinary(w io.Writer) error { l := int64(len(s)) err := s.Kind().MarshalBinary(w) if err != nil { return err } err = binary.Write(w, binary.LittleEndian, l) if err != nil { return err } wl, err := w.Write([]byte(s)) if int64(wl) != l { return fmt.Errorf("short write") } return err } func (s B1onString) UnmarshalBinary(w io.Writer) error { l := int64(len(s)) err := s.Kind().MarshalBinary(w) if err != nil { return err } err = binary.Write(w, binary.LittleEndian, l) if err != nil { return err } wl, err := w.Write([]byte(s)) if int64(wl) != l { return fmt.Errorf("short write") } return err } type B1onBool bool type B1onInt int64 type B1onDouble float64