@@ -15,6 +15,7 @@ import (
1515 "io/ioutil"
1616 "net/http"
1717 "net/url"
18+ //"os"
1819 "reflect"
1920 "strconv"
2021 "strings"
@@ -68,7 +69,7 @@ type Client struct {
6869 // handleResponse specifies a function that is used to handle the response
6970 // returned from server.
7071 // This is used internally by tests for customizing response processing.
71- handleResponse func (httpResp * http.Response , req Request ) (Result , error )
72+ handleResponse func (httpResp * http.Response , req Request , serialVerUsed int16 ) (Result , error )
7273
7374 // isCloud represents whether the client connects to the cloud service or
7475 // cloud simulator.
@@ -1103,7 +1104,7 @@ func (c *Client) doExecute(ctx context.Context, req Request, data []byte, serial
11031104 continue
11041105 }
11051106
1106- result , err = c .handleResponse (httpResp , req )
1107+ result , err = c .handleResponse (httpResp , req , serialVerUsed )
11071108 // Cancel request context after response body has been read.
11081109 reqCancel ()
11091110 if err != nil {
@@ -1348,14 +1349,20 @@ func (c *Client) signHTTPRequest(httpReq *http.Request) error {
13481349// will be sent to the server. The serial version is always written followed by
13491350// the actual request payload.
13501351func (c * Client ) serializeRequest (req Request ) (data []byte , serialVerUsed int16 , err error ) {
1351- wr := binary .NewWriter ()
13521352 serialVerUsed = c .serialVersion
1353+ wr := binary .NewWriter ()
13531354 if _ , err = wr .WriteSerialVersion (serialVerUsed ); err != nil {
13541355 return nil , 0 , err
13551356 }
13561357
1357- if err = req .serialize (wr , serialVerUsed ); err != nil {
1358- return nil , 0 , err
1358+ if serialVerUsed >= 4 {
1359+ if err = req .serialize (wr , serialVerUsed ); err != nil {
1360+ return nil , 0 , err
1361+ }
1362+ } else {
1363+ if err = req .serializeV3 (wr , serialVerUsed ); err != nil {
1364+ return nil , 0 , err
1365+ }
13591366 }
13601367
13611368 return wr .Bytes (), serialVerUsed , nil
@@ -1366,7 +1373,7 @@ func (c *Client) serializeRequest(req Request) (data []byte, serialVerUsed int16
13661373// If the http response status code is 200, this method reads in response
13671374// content and parses them as an appropriate result suitable for the request.
13681375// Otherwise, it returns the http error.
1369- func (c * Client ) processResponse (httpResp * http.Response , req Request ) (Result , error ) {
1376+ func (c * Client ) processResponse (httpResp * http.Response , req Request , serialVerUsed int16 ) (Result , error ) {
13701377 data , err := ioutil .ReadAll (httpResp .Body )
13711378 httpResp .Body .Close ()
13721379 if err != nil {
@@ -1375,31 +1382,41 @@ func (c *Client) processResponse(httpResp *http.Response, req Request) (Result,
13751382
13761383 if httpResp .StatusCode == http .StatusOK {
13771384 c .setSessionCookie (httpResp .Header )
1378- return c .processOKResponse (data , req )
1385+ return c .processOKResponse (data , req , serialVerUsed )
13791386 }
13801387
13811388 return nil , c .processNotOKResponse (data , httpResp .StatusCode )
13821389}
13831390
1384- func (c * Client ) processOKResponse (data []byte , req Request ) (Result , error ) {
1391+ func (c * Client ) processOKResponse (data []byte , req Request , serialVerUsed int16 ) (res Result , err error ) {
13851392 buf := bytes .NewBuffer (data )
13861393 rd := binary .NewReader (buf )
1387- code , err := rd .ReadByte ()
1394+
1395+ var code int
1396+ if serialVerUsed >= 4 {
1397+ if res , code , err = req .deserialize (rd , serialVerUsed ); err != nil {
1398+ return nil , wrapResponseErrors (int (code ), err .Error ())
1399+ }
1400+ if queryReq , ok := req .(* QueryRequest ); ok && ! queryReq .isSimpleQuery () {
1401+ queryReq .driver .client = c
1402+ }
1403+ return res , nil
1404+ }
1405+
1406+ // V3
1407+ bcode , err := rd .ReadByte ()
13881408 if err != nil {
13891409 return nil , err
13901410 }
1391-
1411+ code = int ( bcode )
13921412 // A zero byte represents the operation succeeded.
13931413 if code == 0 {
1394- res , err := req .deserialize (rd , c .serialVersion )
1395- if err != nil {
1414+ if res , err = req .deserializeV3 (rd , serialVerUsed ); err != nil {
13961415 return nil , err
13971416 }
1398-
13991417 if queryReq , ok := req .(* QueryRequest ); ok && ! queryReq .isSimpleQuery () {
14001418 queryReq .driver .client = c
14011419 }
1402-
14031420 return res , nil
14041421 }
14051422
@@ -1548,6 +1565,7 @@ func (c *Client) decrementSerialVersion(serialVerUsed int16) bool {
15481565 }
15491566 if c .serialVersion > 2 {
15501567 c .serialVersion --
1568+ c .logger .Fine ("Decremented serial version to %d\n " , c .serialVersion )
15511569 return true
15521570 }
15531571 return false
@@ -1558,6 +1576,11 @@ func (c *Client) GetSerialVersion() int16 {
15581576 return c .serialVersion
15591577}
15601578
1579+ // SetSerialVersion is used for tests. Do not use this in regular client code.
1580+ func (c * Client ) SetSerialVersion (sVer int16 ) {
1581+ c .serialVersion = sVer
1582+ }
1583+
15611584func (c * Client ) oneTimeMessage (msg string ) {
15621585 if _ , ok := c .oneTimeMessages [msg ]; ok == false {
15631586 c .oneTimeMessages [msg ] = struct {}{}
0 commit comments