Skip to content

Commit

Permalink
more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lewgun committed Aug 15, 2017
1 parent 015029c commit bdd8e1f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func Encode(m *Message) ([]byte, error) {
return buf, nil
}

// Decode unmarshals bytes slice to a message
// Decode unmarshal the bytes slice to a message
// See ref: https://github.com/lonnng/nano/blob/master/docs/communication_protocol.md
func Decode(data []byte) (*Message, error) {
if len(data) < msgHeadLength {
Expand Down
5 changes: 5 additions & 0 deletions internal/packet/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"fmt"
)

// PacketType represents the network packet's type such as: handshake and so on.
type PacketType byte

const (
Expand All @@ -36,18 +37,22 @@ const (
Kick = 0x05 // disconnect message from server
)

// ErrWrongPacketType represents a wrong packet type.
var ErrWrongPacketType = errors.New("wrong packet type")

// Packet represents a network packet.
type Packet struct {
Type PacketType
Length int
Data []byte
}

//New create a Packet instance.
func New() *Packet {
return &Packet{}
}

//String represents the Packet's in text mode.
func (p *Packet) String() string {
return fmt.Sprintf("Type: %d, Length: %d, Data: %s", p.Type, p.Length, string(p.Data))
}

0 comments on commit bdd8e1f

Please sign in to comment.