@@ -10,17 +10,27 @@ import (
10
10
)
11
11
12
12
type Response interface {
13
+ // Header returns a response header.
13
14
Header () Header
15
+ // Decode decodes a response.
16
+ // After a first Decode call,
17
+ // all next calls will return the result of a first one
18
+ // and no decoding will be done.
14
19
Decode () ([]interface {}, error )
20
+ // DecodeTyped decodes a response into a given container res.
21
+ // This method could be called multiple times.
15
22
DecodeTyped (res interface {}) error
16
23
}
17
24
18
25
type baseResponse struct {
26
+ // header is a response header.
19
27
header Header
20
28
// data contains deserialized data for untyped requests.
21
- data []interface {}
22
- buf smallBuf
23
- decoded bool
29
+ data []interface {}
30
+ buf smallBuf
31
+ // Was the Decode() func called for this response.
32
+ decoded bool
33
+ // Was the DecodeTyped() func called for this response.
24
34
decodedTyped bool
25
35
err error
26
36
}
@@ -39,6 +49,7 @@ func createBaseResponse(header Header, body io.Reader) (baseResponse, error) {
39
49
return baseResponse {header : header , buf : smallBuf {b : data }}, nil
40
50
}
41
51
52
+ // PushResponse is used for push requests for the Future.
42
53
type PushResponse struct {
43
54
baseResponse
44
55
}
@@ -51,18 +62,24 @@ func createPushResponse(header Header, body io.Reader) (Response, error) {
51
62
return & PushResponse {resp }, nil
52
63
}
53
64
65
+ // SelectResponse is used for the select requests.
66
+ // It might contain a position descriptor of the last selected tuple.
54
67
type SelectResponse struct {
55
68
baseResponse
56
69
// pos contains a position descriptor of last selected tuple.
57
70
pos []byte
58
71
}
59
72
73
+ // PrepareResponse is used for the prepare requests.
74
+ // It might contain meta-data and sql info.
60
75
type PrepareResponse struct {
61
76
baseResponse
62
77
metaData []ColumnMetaData
63
78
sqlInfo SQLInfo
64
79
}
65
80
81
+ // ExecuteResponse is used for the execute requests.
82
+ // It might contain meta-data and sql info.
66
83
type ExecuteResponse struct {
67
84
baseResponse
68
85
metaData []ColumnMetaData
@@ -83,9 +100,12 @@ type SQLInfo struct {
83
100
InfoAutoincrementIds []uint64
84
101
}
85
102
103
+ // Header is a response header.
86
104
type Header struct {
105
+ // RequestId is an id of a corresponding request.
87
106
RequestId uint32
88
- Code int
107
+ // Code is a response code.
108
+ Code int
89
109
}
90
110
91
111
func (meta * ColumnMetaData ) DecodeMsgpack (d * msgpack.Decoder ) error {
@@ -786,41 +806,52 @@ func (resp *baseResponse) Header() Header {
786
806
return resp .header
787
807
}
788
808
809
+ // Pos returns a position descriptor of the last selected tuple for the SelectResponse.
810
+ // If the response was not decoded, this method will call Decode().
789
811
func (resp * SelectResponse ) Pos () ([]byte , error ) {
790
812
if ! resp .decoded && ! resp .decodedTyped {
791
813
resp .Decode ()
792
814
}
793
815
return resp .pos , resp .err
794
816
}
795
817
818
+ // MetaData returns PrepareResponse meta-data.
819
+ // If the response was not decoded, this method will call Decode().
796
820
func (resp * PrepareResponse ) MetaData () ([]ColumnMetaData , error ) {
797
821
if ! resp .decoded && ! resp .decodedTyped {
798
822
resp .Decode ()
799
823
}
800
824
return resp .metaData , resp .err
801
825
}
802
826
827
+ // SQLInfo returns PrepareResponse sql info.
828
+ // If the response was not decoded, this method will call Decode().
803
829
func (resp * PrepareResponse ) SQLInfo () (SQLInfo , error ) {
804
830
if ! resp .decoded && ! resp .decodedTyped {
805
831
resp .Decode ()
806
832
}
807
833
return resp .sqlInfo , resp .err
808
834
}
809
835
836
+ // MetaData returns ExecuteResponse meta-data.
837
+ // If the response was not decoded, this method will call Decode().
810
838
func (resp * ExecuteResponse ) MetaData () ([]ColumnMetaData , error ) {
811
839
if ! resp .decoded && ! resp .decodedTyped {
812
840
resp .Decode ()
813
841
}
814
842
return resp .metaData , resp .err
815
843
}
816
844
845
+ // SQLInfo returns ExecuteResponse sql info.
846
+ // If the response was not decoded, this method will call Decode().
817
847
func (resp * ExecuteResponse ) SQLInfo () (SQLInfo , error ) {
818
848
if ! resp .decoded && ! resp .decodedTyped {
819
849
resp .Decode ()
820
850
}
821
851
return resp .sqlInfo , resp .err
822
852
}
823
853
854
+ // String implements Stringer interface.
824
855
func (resp * baseResponse ) String () (str string ) {
825
856
if resp .header .Code == OkCode {
826
857
return fmt .Sprintf ("<%d OK %v>" , resp .header .RequestId , resp .data )
0 commit comments