/**
 * @Author: LiXiang
 * @Data: 2020/1/4 下午2:43
 */
package tpro

import (
	"io"
	"net"
)

// TPSession 一条连接
type TPSession interface {
	SessionId() string
	Send(msg []byte) (int, error)
	Close() error
	io.Writer
}

func NewTPSession(conn net.Conn, sessionId string) TPSession {
	return &tpSession{
		conn:      conn,
		sessionId: sessionId,
	}
}

type tpSession struct {
	conn      net.Conn
	sessionId string
}

func (t *tpSession) Write(p []byte) (n int, err error) {
	return t.conn.Write(p)
}

func (t *tpSession) SessionId() string {
	return t.sessionId
}

func (t *tpSession) Send(msg []byte) (int, error) {
	return t.conn.Write(msg)
}
func (t *tpSession) Close() error {
	return t.conn.Close()
}
