Documentation
¶
Overview ¶
Example (Bytes) ¶
input := []byte{
// frame length +1
11,
// message kind: Person v2
1,
// age
0, 21,
// siblings
0, 3,
// len of name +1
5,
// name
'J', 'a', 'n', 'e',
// frame length +1
10,
// message kind: Person v2
1,
// age
0, 30,
// siblings
0, 0,
// len of name +1
4,
// name
'J', 'o', 'e',
}
framed := chitin.NewFramedView(input)
for {
buf, err := framed.Next()
if err == io.EOF {
break
}
if err != nil {
log.Fatal(err)
}
msg, err := person.NewMyProtocolView(buf)
if err != nil {
log.Fatal(err)
}
switch view := msg.(type) {
case *person.PersonV2View:
fmt.Printf("%q is %d years old.\n", view.Name(), view.Age())
default:
log.Fatalf("unknown message type: %T", msg)
}
}
Output: "Jane" is 21 years old. "Joe" is 30 years old.
Example (Messages) ¶
input := []byte{
// frame length +1
11,
// message kind: Person v2
1,
// age
0, 21,
// siblings
0, 3,
// len of name +1
5,
// name
'J', 'a', 'n', 'e',
// frame length +1
10,
// message kind: Person v2
1,
// age
0, 30,
// siblings
0, 0,
// len of name +1
4,
// name
'J', 'o', 'e',
}
framed := person.NewFramedMyProtocolView(input)
for {
msg, err := framed.Next()
if err == io.EOF {
break
}
if err != nil {
log.Fatal(err)
}
switch view := msg.(type) {
case *person.PersonV2View:
fmt.Printf("%q is %d years old.\n", view.Name(), view.Age())
default:
log.Fatalf("unknown message type: %T", msg)
}
}
Output: "Jane" is 21 years old. "Joe" is 30 years old.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FramedMyProtocolView ¶
type FramedMyProtocolView struct {
// contains filtered or unexported fields
}
func NewFramedMyProtocolView ¶
func NewFramedMyProtocolView(data []byte) *FramedMyProtocolView
func (*FramedMyProtocolView) Next ¶
func (v *FramedMyProtocolView) Next() (MyProtocolMessage, error)
type MyProtocolMessage ¶
type MyProtocolMessage interface {
// contains filtered or unexported methods
}
func NewMyProtocolView ¶
func NewMyProtocolView(data []byte) (MyProtocolMessage, error)
type PersonV2View ¶
type PersonV2View struct {
// contains filtered or unexported fields
}
func NewPersonV2View ¶
func NewPersonV2View(data []byte) (*PersonV2View, error)
func (*PersonV2View) Age ¶
func (v *PersonV2View) Age() uint16
func (*PersonV2View) Name ¶
func (v *PersonV2View) Name() string
Name returns a view of the name. Caller must not keep references to it past the lifetime of the view.
If the message is truncated, returns an empty string.
func (*PersonV2View) Siblings ¶
func (v *PersonV2View) Siblings() uint16
Click to show internal directories.
Click to hide internal directories.