forked from chobie/momonga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pubcomp.go
37 lines (30 loc) · 793 Bytes
/
pubcomp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2014, Shuhei Tanuma. All rights reserved.
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file.
package mqtt
import (
"encoding/binary"
"encoding/json"
"io"
)
type PubcompMessage struct {
FixedHeader
PacketIdentifier uint16
}
func (self *PubcompMessage) decode(reader io.Reader) error {
binary.Read(reader, binary.BigEndian, &self.PacketIdentifier)
return nil
}
func (self *PubcompMessage) WriteTo(w io.Writer) (int64, error) {
var fsize = 2
size, err := self.FixedHeader.writeTo(fsize, w)
if err != nil {
return 0, err
}
binary.Write(w, binary.BigEndian, self.PacketIdentifier)
return int64(size) + int64(fsize), nil
}
func (self *PubcompMessage) String() string {
b, _ := json.Marshal(self)
return string(b)
}