123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package b1_test
- import (
- "bytes"
- "encoding/binary"
- "fmt"
- "src.eruta.nl/beoran/bdjncl/b1"
- )
- func ExampleMessage() {
- tm := b1.MakeMessage(123, 1, 2, "/jobs", []byte("body text"), "key1", "val1", "key2", "val2")
- ss := b1.MakeWire("Hello B1.")
- buf := bytes.Buffer{}
- err := binary.Write(&buf, binary.LittleEndian, ss)
- if err != nil {
- fmt.Printf("error: %s\n", err)
- }
- s2 := b1.Wire{}
- err = binary.Read(&buf, binary.LittleEndian, &s2)
- if err != nil {
- fmt.Printf("error: %s\n", err)
- }
- fmt.Println(s2.Len)
- fmt.Println(s2.String())
- buf = bytes.Buffer{}
- err = binary.Write(&buf, binary.LittleEndian, tm.MessageHeader)
- if err != nil {
- fmt.Printf("error: %s\n", err)
- }
- t2 := b1.MessageHeader{}
- err = binary.Read(&buf, binary.LittleEndian, &t2)
- if err != nil {
- fmt.Printf("error: %s\n", err)
- }
- fmt.Println(t2.Method.String())
- buf = bytes.Buffer{}
- tm.MarshalTo(&buf)
- m2 := b1.Message{}
- err = m2.UnmarshalFrom(&buf)
- if err != nil {
- fmt.Printf("error: %s\n", err)
- }
- fmt.Println(m2.Method)
- //output: 9
- //Hello B1.
- ///jobs
- ///jobs
- }
|