func (c *serverCodec) ReadRequestBody(x interface{}) error { if x == nil { return nil } params := c.req.Body.Content.Params.(*Params) return mcpack.Unmarshal(params.Data, &requestParams{x}) }
func (c *clientCodec) ReadResponseBody(x interface{}) error { if x == nil { return nil } params := c.resp.Body.Content.Params.(*Params) return mcpack.Unmarshal(params.Data, &resultParams{x}) }
func (d *Decoder) Decode(h *Head, m interface{}) error { if d.err != nil { return d.err } d.reset() d.resizeIfNeeded(HEAD_SIZE) _, err := d.r.Read(d.buf[:HEAD_SIZE]) if err != nil { return err } d.buf = d.buf[:HEAD_SIZE] err = h.Unmarshal(d.buf) if err != nil { return err } d.resizeIfNeeded(int(h.BodyLen)) _, err = d.r.Read(d.buf[HEAD_SIZE : HEAD_SIZE+h.BodyLen]) if err != nil { return err } d.buf = d.buf[:HEAD_SIZE+h.BodyLen] err = mcpack.Unmarshal(d.buf[HEAD_SIZE:HEAD_SIZE+h.BodyLen], m) if err != nil { return err } return nil }
func (c *Client) Call(args interface{}, reply interface{}) error { content, err := mcpack.Marshal(args) if err != nil { return err } resp, err := c.Client.Do(npc.NewRequest(bytes.NewReader(content))) if err != nil { return err } return mcpack.Unmarshal(resp.Body, reply) }
func main() { sendMsg := Msg{ Name: "foo", Age: 18, Id: 112348, Notes: []Record{{1}, {2}, {3}}, Stage: []uint32{7, 8, 9}, BinaryData: []byte("nice"), } jsonrequest, _ := json.Marshal(sendMsg) fmt.Println(string(jsonrequest)) /////////////// voiceguidesidentify := Voiceguidesidentify{} voiceguidesidentify.Fullreplace_query = "qqqqqqq" voiceguidesidentify.Fullreplace_strategy = 0 voiceguidesidentify.Is_fullreplace = true voiceguidesidentify.Last_query = "wwwwww" voiceguidesidentify.Strategy_type = 1 danormalanalysis := Danormalanalysis{} danormalanalysis.Dummy = 0 danormalanalysis.Voiceguidesidentify = voiceguidesidentify normal := Normal{} normal.Dummy = 0 normal.Danormalanalysis = danormalanalysis result := Result{} result.Normal = normal reply := Reply{} reply.Result = []Result{result} jsonresult, _ := json.Marshal(reply) fmt.Println(string(jsonresult)) ////////////////////////// content, err := mcpack.Marshal(reply) if err != nil { fmt.Println(err) } other := Reply{} //new(Reply) rr := mcpack.Unmarshal(content, other) fmt.Println(other) fmt.Println(rr) jsonother, _ := json.Marshal(other) fmt.Println(string(jsonother)) }