Merge branch 'master' into 0.2-dev
This commit is contained in:
commit
9d7a29fe26
@ -19,10 +19,10 @@ var (
|
|||||||
func getError(data []byte) (err error) {
|
func getError(data []byte) (err error) {
|
||||||
rel := bytes.SplitN(data, []byte{'\x00'}, 2)
|
rel := bytes.SplitN(data, []byte{'\x00'}, 2)
|
||||||
if len(rel) != 2 {
|
if len(rel) != 2 {
|
||||||
err = fmt.Errorf("Not a error data: %V", data)
|
err = fmt.Errorf("Not a error data: %v", data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = errors.New(fmt.Sprintf("%s: %s", rel[0], rel[1]))
|
err = fmt.Errorf("%s: %s", rel[0], rel[1])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,17 +57,17 @@ func (resp *Response) Update() (data []byte, err error) {
|
|||||||
func decodeResponse(data []byte) (resp *Response, l int, err error) {
|
func decodeResponse(data []byte) (resp *Response, l int, err error) {
|
||||||
a := len(data)
|
a := len(data)
|
||||||
if a < minPacketLength { // valid package should not less 12 bytes
|
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
|
return
|
||||||
}
|
}
|
||||||
dl := int(binary.BigEndian.Uint32(data[8:12]))
|
dl := int(binary.BigEndian.Uint32(data[8:12]))
|
||||||
if a < minPacketLength+dl {
|
if a < minPacketLength+dl {
|
||||||
err = fmt.Errorf("Invalid data: %V", data)
|
err = fmt.Errorf("Invalid data: %v", data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dt := data[minPacketLength : dl+minPacketLength]
|
dt := data[minPacketLength : dl+minPacketLength]
|
||||||
if len(dt) != int(dl) { // length not equal
|
if len(dt) != int(dl) { // length not equal
|
||||||
err = fmt.Errorf("Invalid data: %V", data)
|
err = fmt.Errorf("Invalid data: %v", data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp = getResponse()
|
resp = getResponse()
|
||||||
@ -82,7 +82,7 @@ func decodeResponse(data []byte) (resp *Response, l int, err error) {
|
|||||||
resp.Handle = string(s[0])
|
resp.Handle = string(s[0])
|
||||||
resp.Data = s[1]
|
resp.Data = s[1]
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("Invalid data: %V", data)
|
err = fmt.Errorf("Invalid data: %v", data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case dtEchoRes:
|
case dtEchoRes:
|
||||||
@ -97,7 +97,7 @@ func decodeResponse(data []byte) (resp *Response, l int, err error) {
|
|||||||
func (resp *Response) Status() (status *Status, err error) {
|
func (resp *Response) Status() (status *Status, err error) {
|
||||||
data := bytes.SplitN(resp.Data, []byte{'\x00'}, 2)
|
data := bytes.SplitN(resp.Data, []byte{'\x00'}, 2)
|
||||||
if len(data) != 2 {
|
if len(data) != 2 {
|
||||||
err = fmt.Errorf("Invalid data: %V", resp.Data)
|
err = fmt.Errorf("Invalid data: %v", resp.Data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
status = &Status{}
|
status = &Status{}
|
||||||
@ -121,7 +121,7 @@ func (resp *Response) Status() (status *Status, err error) {
|
|||||||
func (resp *Response) _status() (status *Status, err error) {
|
func (resp *Response) _status() (status *Status, err error) {
|
||||||
data := bytes.SplitN(resp.Data, []byte{'\x00'}, 4)
|
data := bytes.SplitN(resp.Data, []byte{'\x00'}, 4)
|
||||||
if len(data) != 4 {
|
if len(data) != 4 {
|
||||||
err = fmt.Errorf("Invalid data: %V", resp.Data)
|
err = fmt.Errorf("Invalid data: %v", resp.Data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
status = &Status{}
|
status = &Status{}
|
||||||
|
@ -36,7 +36,7 @@ func main() {
|
|||||||
fallthrough
|
fallthrough
|
||||||
case client.WorkComplate:
|
case client.WorkComplate:
|
||||||
if data, err := resp.Result(); err == nil {
|
if data, err := resp.Result(); err == nil {
|
||||||
log.Printf("RESULT: %V\n", data)
|
log.Printf("RESULT: %v\n", data)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("RESULT: %s\n", err)
|
log.Printf("RESULT: %s\n", err)
|
||||||
}
|
}
|
||||||
@ -44,18 +44,18 @@ func main() {
|
|||||||
fallthrough
|
fallthrough
|
||||||
case client.WorkData:
|
case client.WorkData:
|
||||||
if data, err := resp.Update(); err == nil {
|
if data, err := resp.Update(); err == nil {
|
||||||
log.Printf("UPDATE: %V\n", data)
|
log.Printf("UPDATE: %v\n", data)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("UPDATE: %V, %s\n", data, err)
|
log.Printf("UPDATE: %v, %s\n", data, err)
|
||||||
}
|
}
|
||||||
case client.WorkStatus:
|
case client.WorkStatus:
|
||||||
if data, err := resp.Status(); err == nil {
|
if data, err := resp.Status(); err == nil {
|
||||||
log.Printf("STATUS: %V\n", data)
|
log.Printf("STATUS: %v\n", data)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("STATUS: %s\n", err)
|
log.Printf("STATUS: %s\n", err)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log.Printf("UNKNOWN: %V", resp.Data)
|
log.Printf("UNKNOWN: %v", resp.Data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handle, err := c.Do("ToUpper", echo, client.JobNormal, jobHandler)
|
handle, err := c.Do("ToUpper", echo, client.JobNormal, jobHandler)
|
||||||
@ -66,7 +66,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
log.Printf("%t", status)
|
log.Printf("%v", *status)
|
||||||
|
|
||||||
_, err = c.Do("Foobar", echo, client.JobNormal, jobHandler)
|
_, err = c.Do("Foobar", echo, client.JobNormal, jobHandler)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,10 +17,10 @@ var (
|
|||||||
func getError(data []byte) (err error) {
|
func getError(data []byte) (err error) {
|
||||||
rel := bytes.SplitN(data, []byte{'\x00'}, 2)
|
rel := bytes.SplitN(data, []byte{'\x00'}, 2)
|
||||||
if len(rel) != 2 {
|
if len(rel) != 2 {
|
||||||
err = fmt.Errorf("Not a error data: %V", data)
|
err = fmt.Errorf("Not a error data: %v", data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = errors.New(fmt.Sprintf("%s: %s", rel[0], rel[1]))
|
err = fmt.Errorf("%s: %s", rel[0], rel[1])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,17 +87,17 @@ func (inpack *inPack) UpdateStatus(numerator, denominator int) {
|
|||||||
// Decode job from byte slice
|
// Decode job from byte slice
|
||||||
func decodeInPack(data []byte) (inpack *inPack, l int, err error) {
|
func decodeInPack(data []byte) (inpack *inPack, l int, err error) {
|
||||||
if len(data) < minPacketLength { // valid package should not less 12 bytes
|
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
|
return
|
||||||
}
|
}
|
||||||
dl := int(binary.BigEndian.Uint32(data[8:12]))
|
dl := int(binary.BigEndian.Uint32(data[8:12]))
|
||||||
if len(data) < (dl + minPacketLength) {
|
if len(data) < (dl + minPacketLength) {
|
||||||
err = fmt.Errorf("Not enough data: %V", data)
|
err = fmt.Errorf("Not enough data: %v", data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dt := data[minPacketLength : dl+minPacketLength]
|
dt := data[minPacketLength : dl+minPacketLength]
|
||||||
if len(dt) != int(dl) { // length not equal
|
if len(dt) != int(dl) { // length not equal
|
||||||
err = fmt.Errorf("Invalid data: %V", data)
|
err = fmt.Errorf("Invalid data: %v", data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
inpack = getInPack()
|
inpack = getInPack()
|
||||||
|
Loading…
Reference in New Issue
Block a user