From 058cf57fbe97fcac8996c26059bcba01f82ac954 Mon Sep 17 00:00:00 2001 From: Eric <xplzv@126.com> Date: Wed, 20 Nov 2019 10:32:37 +0800 Subject: [PATCH] stash --- pkg/proxy/newcommandparser.go | 25 ++++++++++++++----------- pkg/proxy/parser.go | 8 +++----- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pkg/proxy/newcommandparser.go b/pkg/proxy/newcommandparser.go index 8a1dca4..34b6341 100644 --- a/pkg/proxy/newcommandparser.go +++ b/pkg/proxy/newcommandparser.go @@ -8,8 +8,8 @@ import ( ) type commandInput struct { - readFromUserInput bytes.Buffer - readFromServerInput bytes.Buffer + readFromUserInput *bytes.Buffer + readFromServerInput *bytes.Buffer isUserSideValid bool isServerSideValid bool @@ -24,16 +24,18 @@ func (c *commandInput) readFromServer(p []byte) { } func (c *commandInput) Parse() string { - lines, ok := utils.ParseTerminalData(c.readFromUserInput.Bytes()) + lines, ok := utils.ParseTerminalData([]byte(c.readFromUserInput.String())) if ok { fmt.Println("readFromUserInput lines: ", lines) c.readFromUserInput.Reset() c.readFromServerInput.Reset() - return strings.Join(lines, "\r\n") + result := strings.Join(lines, "\r\n") + fmt.Println("readFromUserInput result: ", result, len(result)) + return result } - lines, _ = utils.ParseTerminalData(c.readFromServerInput.Bytes()) + lines, _ = utils.ParseTerminalData([]byte(c.readFromServerInput.String())) fmt.Println("readFromServerInput lines: ", lines) c.readFromUserInput.Reset() c.readFromServerInput.Reset() @@ -41,9 +43,7 @@ func (c *commandInput) Parse() string { } type commandOut struct { - readFromServerOut bytes.Buffer - isUserSideValid bool - isServerSideValid bool + readFromServerOut *bytes.Buffer } func (c *commandOut) readFromServer(p []byte) { @@ -51,8 +51,11 @@ func (c *commandOut) readFromServer(p []byte) { } func (c *commandOut) Parse() string { - lines, _ := utils.ParseTerminalData(c.readFromServerOut.Bytes()) + lines, _ := utils.ParseTerminalData([]byte(c.readFromServerOut.String())) c.readFromServerOut.Reset() - fmt.Println("commandOut: ", lines) - return strings.Join(lines, "\r\n") + result := strings.Join(lines, "\r\n") + fmt.Println("commandOut: ", result) + return result } + + diff --git a/pkg/proxy/parser.go b/pkg/proxy/parser.go index 560e9a1..ecbafc3 100644 --- a/pkg/proxy/parser.go +++ b/pkg/proxy/parser.go @@ -71,15 +71,13 @@ func (p *Parser) initial() { //p.cmdInputParser = NewCmdParser(p.id, CommandInputParserName) //p.cmdOutputParser = NewCmdParser(p.id, CommandOutputParserName) p.cmdInputParser = &commandInput{ - readFromUserInput: bytes.Buffer{}, - readFromServerInput: bytes.Buffer{}, + readFromUserInput: &bytes.Buffer{}, + readFromServerInput: &bytes.Buffer{}, isUserSideValid: false, isServerSideValid: false, } p.cmdOutputParser = &commandOut{ - readFromServerOut: bytes.Buffer{}, - isUserSideValid: false, - isServerSideValid: false, + readFromServerOut: &bytes.Buffer{}, } p.closed = make(chan struct{}) p.cmdRecordChan = make(chan [2]string, 1024) -- 2.18.0