func (h *handler) OnMessage(reader *lendecoder.ReadBuffer) { count := 0 for _, b := range reader.Buffer() { count += int(b) } reply := make([]byte, 2) reply[0] = byte(count >> 8) reply[1] = byte(count) h.writer.Write(reply) }
func (h *handler) OnMessage(reader *lendecoder.ReadBuffer) { defer func() { if err := recover(); err != nil { fmt.Println(err) return } }() checkSum := reader.ReadUnsignedByte() fmt.Printf("CheckSum: %v\n", checkSum) bigOffset := reader.ReadUnsignedByte() fmt.Printf("big offset: %v\n", bigOffset) msgId := reader.ReadUnsignedShort() fmt.Printf("offset: %v\n", msgId>>13) fmt.Printf("Received msg %v\n", msgId&0x1fff) }