Merge branch 'master' into 0.2-dev

This commit is contained in:
Xing Xing 2014-03-07 17:33:16 +08:00
commit 9d7a29fe26
5 changed files with 19 additions and 19 deletions

View File

@ -19,10 +19,10 @@ var (
func getError(data []byte) (err error) {
rel := bytes.SplitN(data, []byte{'\x00'}, 2)
if len(rel) != 2 {
err = fmt.Errorf("Not a error data: %V", data)
err = fmt.Errorf("Not a error data: %v", data)
return
}
err = errors.New(fmt.Sprintf("%s: %s", rel[0], rel[1]))
err = fmt.Errorf("%s: %s", rel[0], rel[1])
return
}

View File

@ -57,17 +57,17 @@ func (resp *Response) Update() (data []byte, err error) {
func decodeResponse(data []byte) (resp *Response, l int, err error) {
a := len(data)
if a < minPacketLength { // valid package should not less 12 bytes
err = fmt.Errorf("Invalid data: %V", data)
err = fmt.Errorf("Invalid data: %v", data)
return
}
dl := int(binary.BigEndian.Uint32(data[8:12]))
if a < minPacketLength+dl {
err = fmt.Errorf("Invalid data: %V", data)
err = fmt.Errorf("Invalid data: %v", data)
return
}
dt := data[minPacketLength : dl+minPacketLength]
if len(dt) != int(dl) { // length not equal
err = fmt.Errorf("Invalid data: %V", data)
err = fmt.Errorf("Invalid data: %v", data)
return
}
resp = getResponse()
@ -82,7 +82,7 @@ func decodeResponse(data []byte) (resp *Response, l int, err error) {
resp.Handle = string(s[0])
resp.Data = s[1]
} else {
err = fmt.Errorf("Invalid data: %V", data)
err = fmt.Errorf("Invalid data: %v", data)
return
}
case dtEchoRes:
@ -97,7 +97,7 @@ func decodeResponse(data []byte) (resp *Response, l int, err error) {
func (resp *Response) Status() (status *Status, err error) {
data := bytes.SplitN(resp.Data, []byte{'\x00'}, 2)
if len(data) != 2 {
err = fmt.Errorf("Invalid data: %V", resp.Data)
err = fmt.Errorf("Invalid data: %v", resp.Data)
return
}
status = &Status{}
@ -121,7 +121,7 @@ func (resp *Response) Status() (status *Status, err error) {
func (resp *Response) _status() (status *Status, err error) {
data := bytes.SplitN(resp.Data, []byte{'\x00'}, 4)
if len(data) != 4 {
err = fmt.Errorf("Invalid data: %V", resp.Data)
err = fmt.Errorf("Invalid data: %v", resp.Data)
return
}
status = &Status{}

View File

@ -36,7 +36,7 @@ func main() {
fallthrough
case client.WorkComplate:
if data, err := resp.Result(); err == nil {
log.Printf("RESULT: %V\n", data)
log.Printf("RESULT: %v\n", data)
} else {
log.Printf("RESULT: %s\n", err)
}
@ -44,18 +44,18 @@ func main() {
fallthrough
case client.WorkData:
if data, err := resp.Update(); err == nil {
log.Printf("UPDATE: %V\n", data)
log.Printf("UPDATE: %v\n", data)
} else {
log.Printf("UPDATE: %V, %s\n", data, err)
log.Printf("UPDATE: %v, %s\n", data, err)
}
case client.WorkStatus:
if data, err := resp.Status(); err == nil {
log.Printf("STATUS: %V\n", data)
log.Printf("STATUS: %v\n", data)
} else {
log.Printf("STATUS: %s\n", err)
}
default:
log.Printf("UNKNOWN: %V", resp.Data)
log.Printf("UNKNOWN: %v", resp.Data)
}
}
handle, err := c.Do("ToUpper", echo, client.JobNormal, jobHandler)
@ -66,7 +66,7 @@ func main() {
if err != nil {
log.Fatalln(err)
}
log.Printf("%t", status)
log.Printf("%v", *status)
_, err = c.Do("Foobar", echo, client.JobNormal, jobHandler)
if err != nil {

View File

@ -17,10 +17,10 @@ var (
func getError(data []byte) (err error) {
rel := bytes.SplitN(data, []byte{'\x00'}, 2)
if len(rel) != 2 {
err = fmt.Errorf("Not a error data: %V", data)
err = fmt.Errorf("Not a error data: %v", data)
return
}
err = errors.New(fmt.Sprintf("%s: %s", rel[0], rel[1]))
err = fmt.Errorf("%s: %s", rel[0], rel[1])
return
}

View File

@ -87,17 +87,17 @@ func (inpack *inPack) UpdateStatus(numerator, denominator int) {
// Decode job from byte slice
func decodeInPack(data []byte) (inpack *inPack, l int, err error) {
if len(data) < minPacketLength { // valid package should not less 12 bytes
err = fmt.Errorf("Invalid data: %V", data)
err = fmt.Errorf("Invalid data: %v", data)
return
}
dl := int(binary.BigEndian.Uint32(data[8:12]))
if len(data) < (dl + minPacketLength) {
err = fmt.Errorf("Not enough data: %V", data)
err = fmt.Errorf("Not enough data: %v", data)
return
}
dt := data[minPacketLength : dl+minPacketLength]
if len(dt) != int(dl) { // length not equal
err = fmt.Errorf("Invalid data: %V", data)
err = fmt.Errorf("Invalid data: %v", data)
return
}
inpack = getInPack()