func TestDecomposeBytes(t *testing.T) { ass := assert.New(t) // buffer is smaller than header { id := "0" name := "test" h := dingo.NewHeader(id, name) h.Append(100000) bs, err := dingo.DecomposeBytes(h, make([]byte, 5)) ass.Nil(bs) ass.NotNil(err) } // buffer is smaller than registry { id := "0" name := "test" h := dingo.NewHeader(id, name) h.Append(100000) b, err := h.Flush(0) ass.Nil(err) h, err = dingo.DecodeHeader(b) ass.Nil(err) bs, err := dingo.DecomposeBytes(h, b) ass.Len(bs, 0) ass.NotNil(err) } }
func (me *testMyMarshaller) DecodeReport(h *dingo.Header, fn interface{}, b []byte) (report *dingo.Report, err error) { var ( msg string count int s int16 e *dingo.Error o *dingo.Option ) bs, _ := dingo.DecomposeBytes(h, b) if len(bs) > 3 { // the report might, or might not containing // returns. json.Unmarshal(bs[0], &msg) json.Unmarshal(bs[1], &count) bs = bs[2:] } json.Unmarshal(bs[0], &s) json.Unmarshal(bs[1], &e) json.Unmarshal(bs[2], &o) report = &dingo.Report{ H: h, P: &dingo.ReportPayload{ S: s, E: e, O: o, R: []interface{}{msg, count}, }, } return }
func (me *testMyMarshaller) DecodeTask(h *dingo.Header, fn interface{}, b []byte) (task *dingo.Task, err error) { var ( n int name string o *dingo.Option ) bs, _ := dingo.DecomposeBytes(h, b) json.Unmarshal(bs[0], &n) json.Unmarshal(bs[1], &name) json.Unmarshal(bs[2], &o) task = &dingo.Task{ H: h, P: &dingo.TaskPayload{ O: o, A: []interface{}{n, name}, }, } return }