[Groonga-commit] groonga/grnci at 2ba650f [master] Update DB.send to take []byte instead of string

Back to archive index

Susumu Yata null+****@clear*****
Thu Feb 18 17:29:11 JST 2016


Susumu Yata	2016-02-18 17:29:11 +0900 (Thu, 18 Feb 2016)

  New Revision: 2ba650ffcb8655f310a23c9d8dc6f373fd8d3c8f
  https://github.com/groonga/grnci/commit/2ba650ffcb8655f310a23c9d8dc6f373fd8d3c8f

  Message:
    Update DB.send to take []byte instead of string

  Modified files:
    db.go

  Modified: db.go (+8 -9)
===================================================================
--- db.go    2016-02-18 16:01:08 +0900 (bef68b5)
+++ db.go    2016-02-18 17:29:11 +0900 (b9b34f5)
@@ -321,14 +321,13 @@ func (db *DB) composeCommand(name string, args []cmdArg) (string, error) {
 	return buf.String(), nil
 }
 
-// send() sends a command.
-func (db *DB) send(cmd string) error {
-	if len(cmd) == 0 {
-		return fmt.Errorf("cmd is empty")
-	}
-	cCmd := C.CString(cmd)
-	defer C.free(unsafe.Pointer(cCmd))
-	rc := C.grn_rc(C.grn_ctx_send(db.ctx, cCmd, C.uint(len(cmd)), C.int(0)))
+// send sends data.
+func (db *DB) send(data []byte) error {
+	var p *C.char
+	if len(data) != 0 {
+		p = (*C.char)(unsafe.Pointer(&data[0]))
+	}
+	rc := C.grn_rc(C.grn_ctx_send(db.ctx, p, C.uint(len(data)), C.int(0)))
 	if (rc != C.GRN_SUCCESS) || (db.ctx.rc != C.GRN_SUCCESS) {
 		return db.errorf("grn_ctx_send() failed: rc = %s", rc)
 	}
@@ -369,7 +368,7 @@ func (db *DB) recv() ([]byte, error) {
 
 // query() executes a command.
 func (db *DB) query(cmd string) ([]byte, error) {
-	if err := db.send(cmd); err != nil {
+	if err := db.send([]byte(cmd)); err != nil {
 		res, _ := db.recv()
 		return res, err
 	}
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index