Skip to content

Commit

Permalink
added int field to command packet for greater flexibility/usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil committed Apr 12, 2010
1 parent 584cca2 commit 1ddc9e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mysql.go
Expand Up @@ -573,7 +573,7 @@ func (mysql *MySQL) command(command byte, arg string) {
case COM_QUIT, COM_INIT_DB, COM_QUERY, COM_PING, COM_STMT_PREPARE:
pkt := new(packetCommand)
pkt.command = command
pkt.arg = arg
pkt.argStr = arg
err = pkt.write(mysql.writer)
}
if err != nil {
Expand Down
19 changes: 13 additions & 6 deletions mysql_packet.go
Expand Up @@ -301,12 +301,14 @@ func (pkt *packetError) read(reader *bufio.Reader) (err os.Error) {
}

/**
* Standard command packet (tells the server to do something defined by arg)
* Standard command packet (tells the server to do something defined by args)
*/
type packetCommand struct {
header *packetHeader
command byte
arg string
argInt uint64
argIntLen uint8
argStr string
}

/**
Expand All @@ -315,16 +317,21 @@ type packetCommand struct {
func (pkt *packetCommand) write(writer *bufio.Writer) (err os.Error) {
// Construct packet header
pkt.header = new(packetHeader)
pkt.header.length = 1 + uint32(len(pkt.arg))
pkt.header.length = 1 + uint32(pkt.argIntLen) + uint32(len(pkt.argStr))
pkt.header.sequence = 0
err = pkt.header.write(writer)
if err != nil { return err }
// Write command
err = writer.WriteByte(byte(pkt.command))
if err != nil { return err }
// Write arg
if len(pkt.arg) > 0 {
_, err = writer.WriteString(pkt.arg)
// Write argInt
if pkt.argIntLen > 0 {
err = writeNumber(writer, pkt.argInt, pkt.argIntLen)
if err != nil { return err }
}
// Write argStr
if len(pkt.argStr) > 0 {
_, err = writer.WriteString(pkt.argStr)
if err != nil { return err }
}
// Flush
Expand Down

0 comments on commit 1ddc9e8

Please sign in to comment.