Skip to content

Commit 7415160

Browse files
committed
Add missing comments
1 parent 7455753 commit 7415160

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

response.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,27 @@ import (
1010
)
1111

1212
type Response interface {
13+
// Header returns a response header.
1314
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.
1419
Decode() ([]interface{}, error)
20+
// DecodeTyped decodes a response into a given container res.
21+
// This method could be called multiple times.
1522
DecodeTyped(res interface{}) error
1623
}
1724

1825
type baseResponse struct {
26+
// header is a response header.
1927
header Header
2028
// 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.
2434
decodedTyped bool
2535
err error
2636
}
@@ -39,6 +49,7 @@ func createBaseResponse(header Header, body io.Reader) (baseResponse, error) {
3949
return baseResponse{header: header, buf: smallBuf{b: data}}, nil
4050
}
4151

52+
// PushResponse is used for push requests for the Future.
4253
type PushResponse struct {
4354
baseResponse
4455
}
@@ -51,18 +62,24 @@ func createPushResponse(header Header, body io.Reader) (Response, error) {
5162
return &PushResponse{resp}, nil
5263
}
5364

65+
// SelectResponse is used for the select requests.
66+
// It might contain a position descriptor of the last selected tuple.
5467
type SelectResponse struct {
5568
baseResponse
5669
// pos contains a position descriptor of last selected tuple.
5770
pos []byte
5871
}
5972

73+
// PrepareResponse is used for the prepare requests.
74+
// It might contain meta-data and sql info.
6075
type PrepareResponse struct {
6176
baseResponse
6277
metaData []ColumnMetaData
6378
sqlInfo SQLInfo
6479
}
6580

81+
// ExecuteResponse is used for the execute requests.
82+
// It might contain meta-data and sql info.
6683
type ExecuteResponse struct {
6784
baseResponse
6885
metaData []ColumnMetaData
@@ -83,9 +100,12 @@ type SQLInfo struct {
83100
InfoAutoincrementIds []uint64
84101
}
85102

103+
// Header is a response header.
86104
type Header struct {
105+
// RequestId is an id of a corresponding request.
87106
RequestId uint32
88-
Code int
107+
// Code is a response code.
108+
Code int
89109
}
90110

91111
func (meta *ColumnMetaData) DecodeMsgpack(d *msgpack.Decoder) error {
@@ -786,41 +806,52 @@ func (resp *baseResponse) Header() Header {
786806
return resp.header
787807
}
788808

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().
789811
func (resp *SelectResponse) Pos() ([]byte, error) {
790812
if !resp.decoded && !resp.decodedTyped {
791813
resp.Decode()
792814
}
793815
return resp.pos, resp.err
794816
}
795817

818+
// MetaData returns PrepareResponse meta-data.
819+
// If the response was not decoded, this method will call Decode().
796820
func (resp *PrepareResponse) MetaData() ([]ColumnMetaData, error) {
797821
if !resp.decoded && !resp.decodedTyped {
798822
resp.Decode()
799823
}
800824
return resp.metaData, resp.err
801825
}
802826

827+
// SQLInfo returns PrepareResponse sql info.
828+
// If the response was not decoded, this method will call Decode().
803829
func (resp *PrepareResponse) SQLInfo() (SQLInfo, error) {
804830
if !resp.decoded && !resp.decodedTyped {
805831
resp.Decode()
806832
}
807833
return resp.sqlInfo, resp.err
808834
}
809835

836+
// MetaData returns ExecuteResponse meta-data.
837+
// If the response was not decoded, this method will call Decode().
810838
func (resp *ExecuteResponse) MetaData() ([]ColumnMetaData, error) {
811839
if !resp.decoded && !resp.decodedTyped {
812840
resp.Decode()
813841
}
814842
return resp.metaData, resp.err
815843
}
816844

845+
// SQLInfo returns ExecuteResponse sql info.
846+
// If the response was not decoded, this method will call Decode().
817847
func (resp *ExecuteResponse) SQLInfo() (SQLInfo, error) {
818848
if !resp.decoded && !resp.decodedTyped {
819849
resp.Decode()
820850
}
821851
return resp.sqlInfo, resp.err
822852
}
823853

854+
// String implements Stringer interface.
824855
func (resp *baseResponse) String() (str string) {
825856
if resp.header.Code == OkCode {
826857
return fmt.Sprintf("<%d OK %v>", resp.header.RequestId, resp.data)

0 commit comments

Comments
 (0)