Beispiel #1
0
//ReadPktLine read pktline from conn
func (gconn *Conn) ReadPktLine() ([]string, error) {
	var pktlBytes [][]byte //pktlBytes := make([][]byte, 0)
	pktLineEder := pktline.NewEncoderDecoder(gconn)
	err := pktLineEder.DecodeUntilFlush(&pktlBytes)
	if err != nil {
		return nil, err
	}
	pktLines := make([]string, len(pktlBytes))
	for i, v := range pktlBytes {
		pktLines[i] = string(bytes.TrimRight(v, "\r\n"))
	}
	return pktLines, err
}
Beispiel #2
0
//receiveWithSideband read data from conn
func (gconn *Conn) receiveWithSideband() (dataType byte, data []byte, done bool, err error) {
	pktLineEder := pktline.NewEncoderDecoder(gconn)
	var line []byte
	err = pktLineEder.Decode(&line)
	if err != nil {
		return
	}
	if line == nil {
		done = true
		return
	}
	dataType = line[0] //first byte
	data = line[1:]    //remain bytes
	//error
	if dataType == ERROR_FRAME {
		err = errors.New(string(data))
		return
	}
	return
}
Beispiel #3
0
//WritePktLine wite pktline to conn
func (gconn *Conn) WritePktLine(line []byte) (int, error) {
	pktLineEder := pktline.NewEncoderDecoder(gconn)
	err := pktLineEder.Encode(line)
	return len(line), err
}