From 95a689b3cf6b574e66ff808c7f9aa60901592c6b Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Wed, 29 Mar 2023 20:48:02 -0400 Subject: [PATCH] Some improvements thanks to ChatGPT 4 --- cluster/service.go | 2 +- command/marshal.go | 2 +- db/db.go | 7 ++++++- http/request_parser.go | 8 +++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cluster/service.go b/cluster/service.go index a8d29ed4..419545c5 100644 --- a/cluster/service.go +++ b/cluster/service.go @@ -216,8 +216,8 @@ func (s *Service) checkCommandPerm(c *Command, perm string) bool { func (s *Service) handleConn(conn net.Conn) { defer conn.Close() + b := make([]byte, protoBufferLengthSize) for { - b := make([]byte, protoBufferLengthSize) _, err := io.ReadFull(conn, b) if err != nil { return diff --git a/command/marshal.go b/command/marshal.go index 1c978625..1fd8cd13 100644 --- a/command/marshal.go +++ b/command/marshal.go @@ -65,7 +65,7 @@ func NewRequestMarshaler() *RequestMarshaler { // Marshal marshals a Requester object, returning a byte slice, a bool // indicating whether the contents are compressed, or an error. func (m *RequestMarshaler) Marshal(r Requester) ([]byte, bool, error) { - stats.Add(numRequests, 0) + stats.Add(numRequests, 1) compress := false stmts := r.GetRequest().GetStatements() diff --git a/db/db.go b/db/db.go index 556e40dc..9cbf1779 100644 --- a/db/db.go +++ b/db/db.go @@ -909,6 +909,11 @@ func normalizeRowValues(row []interface{}, types []string) ([]*command.Parameter for i, v := range row { switch val := v.(type) { case int: + values[i] = &command.Parameter{ + Value: &command.Parameter_I{ + I: int64(val)}, + Name: "", + } case int64: values[i] = &command.Parameter{ Value: &command.Parameter_I{ @@ -985,7 +990,7 @@ func randomString() string { for i := 0; i < 20; i++ { random := rand.Intn(len(chars)) randomChar := chars[random] - output.WriteString(string(randomChar)) + output.WriteByte(randomChar) } return output.String() } diff --git a/http/request_parser.go b/http/request_parser.go index 6ffaeda3..9a481396 100644 --- a/http/request_parser.go +++ b/http/request_parser.go @@ -25,7 +25,7 @@ var ( // ParseRequest generates a set of Statements for a given byte slice. func ParseRequest(b []byte) ([]*command.Statement, error) { - if b == nil { + if len(b) == 0 { return nil, ErrNoStatements } @@ -115,6 +115,12 @@ func makeParameter(name string, i interface{}) (*command.Parameter, error) { switch v := i.(type) { case int: + return &command.Parameter{ + Value: &command.Parameter_I{ + I: int64(v), + }, + Name: name, + }, nil case int64: return &command.Parameter{ Value: &command.Parameter_I{