Skip to content

Commit

Permalink
重命名
Browse files Browse the repository at this point in the history
  • Loading branch information
bg5sbk committed Jun 30, 2015
1 parent 4fce80f commit 99949d7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions codec_self.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ func (_ selfCodecType) NewStreamCodec(r *bufio.Reader, w *bufio.Writer) StreamCo
}
}

type SelfDecode interface {
BinaryDecode(*binary.Reader) error
type SelfDecoder interface {
SelfDecode(*binary.Reader) error
}

type SelfEncode interface {
BinaryEncode(*binary.Writer) error
type SelfEncoder interface {
SelfEncode(*binary.Writer) error
}

type selfPacketCodec struct {
Expand All @@ -43,12 +43,12 @@ type selfPacketCodec struct {

func (codec *selfPacketCodec) DecodePacket(msg interface{}, b []byte) error {
codec.rbuf.Reset(b)
return msg.(SelfDecode).BinaryDecode(codec.r)
return msg.(SelfDecoder).SelfDecode(codec.r)
}

func (codec *selfPacketCodec) EncodePacket(msg interface{}) ([]byte, error) {
codec.wbuf.Reset(codec.wbuf.Data[0:0])
if err := msg.(SelfEncode).BinaryEncode(codec.w); err != nil {
if err := msg.(SelfEncoder).SelfEncode(codec.w); err != nil {
return nil, err
}
return codec.wbuf.Bytes(), nil
Expand All @@ -60,14 +60,14 @@ type selfStreamCodec struct {
}

func (codec selfStreamCodec) DecodeStream(msg interface{}) error {
if err := msg.(SelfDecode).BinaryDecode(codec.r); err != nil {
if err := msg.(SelfDecoder).SelfDecode(codec.r); err != nil {
return err
}
return codec.r.Error()
}

func (codec selfStreamCodec) EncodeStream(msg interface{}) error {
if err := msg.(SelfEncode).BinaryEncode(codec.w); err != nil {
if err := msg.(SelfEncoder).SelfEncode(codec.w); err != nil {
return err
}
return codec.w.Flush()
Expand Down
8 changes: 4 additions & 4 deletions gateway/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const (
CMD_PONG = 7
)

var _ link.SelfEncode = &gatewayMsg{}
var _ link.SelfDecode = &gatewayMsg{}
var _ link.SelfEncoder = &gatewayMsg{}
var _ link.SelfDecoder = &gatewayMsg{}

type gatewayMsg struct {
Command uint8
Expand All @@ -25,7 +25,7 @@ type gatewayMsg struct {
Data []byte
}

func (msg *gatewayMsg) BinaryDecode(r *binary.Reader) error {
func (msg *gatewayMsg) SelfDecode(r *binary.Reader) error {
msg.Command = r.ReadUint8()
switch msg.Command {
case CMD_NEW_1:
Expand All @@ -50,7 +50,7 @@ func (msg *gatewayMsg) BinaryDecode(r *binary.Reader) error {
return nil
}

func (msg *gatewayMsg) BinaryEncode(w *binary.Writer) error {
func (msg *gatewayMsg) SelfEncode(w *binary.Writer) error {
w.WriteUint8(msg.Command)
switch msg.Command {
case CMD_NEW_1:
Expand Down
4 changes: 2 additions & 2 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ type TestObject struct {
X, Y, Z int
}

func (obj *TestObject) BinaryDecode(r *binary.Reader) error {
func (obj *TestObject) SelfDecode(r *binary.Reader) error {
obj.X = int(r.ReadVarint())
obj.Y = int(r.ReadVarint())
obj.Z = int(r.ReadVarint())
return nil
}

func (obj *TestObject) BinaryEncode(w *binary.Writer) error {
func (obj *TestObject) SelfEncode(w *binary.Writer) error {
w.WriteVarint(int64(obj.X))
w.WriteVarint(int64(obj.Y))
w.WriteVarint(int64(obj.Z))
Expand Down

0 comments on commit 99949d7

Please sign in to comment.