Beispiel #1
0
func packEC(paramMap map[string]string) *Request {
	sid := make([]uint32, 1)
	sid[0] = 2014
	urlPack := UrlPack{} //UrlPack{voice_search: 2}
	urlPack.Voice_search = 2
	byteUrlPack, _ := mcpack.Marshal(urlPack)
	normalreq := Normalreq{} //{sid: sid, rsse_num: 10, rsse_type: 139}
	normalreq.Sid = sid
	normalreq.Rsse_num = 10
	normalreq.Rsse_type = 139
	normalreq.UrlPack = byteUrlPack
	if paramMap["character"] == "utf-8" || paramMap["character"] == "utf8" {
		enc := mahonia.NewEncoder("gbk")
		gbk := enc.ConvertString(paramMap["query"])
		normalreq.Word = gbk
	} else {
		normalreq.Word = paramMap["query"]
	}

	req := Req{}
	req.Cmd = 0
	req.Cmd64 = 0
	cmdreq := make([]uint64, 2)
	cmdreq[0] = 0
	cmdreq[1] = 2097152
	req.Cmdreq = cmdreq
	req.Normalreq = normalreq
	request := Request{}
	reqList := make([]Req, 1)
	reqList[0] = req
	request.Req = reqList
	request.Req_module = "imms"
	request.Server = "mmsda"
	return &request
}
Beispiel #2
0
func packCQ(paramMap map[string]string) *Request {
	sid := make([]uint32, 1)
	sid[0] = 2014
	urlPack := UrlPackCQ{} //UrlPack{voice_search: 2}
	urlPack.Voice_search = 2
	if _, ok := paramMap["speachid"]; ok {
		speachid, err := strconv.Atoi(paramMap["speachid"])
		if err == nil {
			urlPack.Speachid = int32(speachid)
		}

	}
	enc := mahonia.NewEncoder("gbk")
	if _, ok := paramMap["lq"]; ok {
		if paramMap["character"] == "utf-8" || paramMap["character"] == "utf8" {
			mmsuse := enc.ConvertString(paramMap["lq"])
			urlPack.Mmsuse = "lq@" + mmsuse
		} else {
			urlPack.Mmsuse = "lq@" + paramMap["lq"]
		}
	} else {
		if _, okbaidu := paramMap["baiduid"]; okbaidu {
			urlPack.Baiduid = paramMap["baiduid"]
		}
	}

	byteUrlPack, _ := mcpack.Marshal(urlPack)
	normalreq := Normalreq{} //{sid: sid, rsse_num: 10, rsse_type: 139}
	normalreq.Sid = sid
	normalreq.Rsse_num = 10
	normalreq.Rsse_type = 139
	normalreq.UrlPack = byteUrlPack
	if paramMap["character"] == "utf-8" || paramMap["character"] == "utf8" {
		//enc := mahonia.NewEncoder("gbk")
		gbk := enc.ConvertString(paramMap["query"])
		normalreq.Word = gbk
	} else {
		normalreq.Word = paramMap["query"]
	}

	req := Req{}
	req.Cmd = 0
	req.Cmd64 = 0
	cmdreq := make([]uint64, 2)
	cmdreq[0] = 0
	cmdreq[1] = 2097152
	req.Cmdreq = cmdreq
	req.Normalreq = normalreq
	request := Request{}
	reqList := make([]Req, 1)
	reqList[0] = req
	request.Req = reqList
	request.Req_module = "imms"
	request.Server = "mmsda"
	return &request
}
Beispiel #3
0
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)
}
Beispiel #4
0
func main() {
	sid := make([]uint32, 1)
	sid[0] = 2014
	urlPack := UrlPack{} //UrlPack{voice_search: 2}
	urlPack.Voice_search = 2
	byteUrlPack, _ := mcpack.Marshal(urlPack)
	normalreq := Normalreq{} //{sid: sid, rsse_num: 10, rsse_type: 139}
	normalreq.Sid = sid
	normalreq.Rsse_num = 10
	normalreq.Rsse_type = 139
	normalreq.UrlPack = byteUrlPack
	enc := mahonia.NewEncoder("gbk")
	gbk := enc.ConvertString("你好")
	normalreq.Word = gbk

	req := Req{}
	req.Cmd = 0
	req.Cmd64 = 0
	cmdreq := make([]uint64, 2)
	cmdreq[0] = 0
	cmdreq[1] = 2097152
	req.Cmdreq = cmdreq
	req.Normalreq = normalreq
	request := Request{}
	reqList := make([]Req, 1)
	reqList[0] = req
	request.Req = reqList
	request.Req_module = "imms"
	request.Server = "mmsda"
	mcRequet, _ := mcpack.Marshal(request)
	fmt.Println(len(mcRequet))
	conn, err := mcpackrpc.Dial("tcp", "10.144.21.41:2987")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println("conn:", conn)
	connn, _ := conn.(io.ReadWriteCloser)
	clien := mcpackrpc.NewClientCodec(connn)
	fmt.Println("clien:", clien)
}
Beispiel #5
0
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))
}
Beispiel #6
0
func (e *Encoder) Encode(h *Head, m interface{}) error {
	bytes, err := mcpack.Marshal(m)
	if err != nil {
		return err
	}
	h.BodyLen = uint32(len(bytes))
	err = h.Marshal(e.buf[:])
	if err != nil {
		return err
	}
	_, err = e.w.Write(e.buf[:])
	if err != nil {
		return err
	}
	_, err = e.w.Write(bytes)
	if err != nil {
		return err
	}
	return nil
}
Beispiel #7
0
func main() {
	sid := make([]uint32, 1)
	sid[0] = 2014
	urlPack := UrlPack{} //UrlPack{voice_search: 2}
	urlPack.Voice_search = 2
	byteUrlPack, _ := mcpack.Marshal(urlPack)
	normalreq := Normalreq{} //{sid: sid, rsse_num: 10, rsse_type: 139}
	normalreq.Sid = sid
	normalreq.Rsse_num = 10
	normalreq.Rsse_type = 139
	normalreq.UrlPack = byteUrlPack
	//	cd, err := iconv.Open("gbk", "utf-8")
	//	if err != nil {
	//		fmt.Println(err)
	//	}
	//	gbk := cd.ConvString("失落伐克欧洲杯")
	enc := mahonia.NewEncoder("gbk")
	gbk := enc.ConvertString("失落伐克欧洲杯")
	normalreq.Word = gbk
	//jsonnormalreq, _ := json.Marshal(normalreq)
	//fmt.Println(string(jsonnormalreq))

	req := Req{}
	req.Cmd = 0
	req.Cmd64 = 0
	cmdreq := make([]uint64, 2)
	cmdreq[0] = 0
	cmdreq[1] = 2097152
	req.Cmdreq = cmdreq
	//req.Sub_cmdreq = cmdreq
	req.Normalreq = normalreq
	request := Request{}
	reqList := make([]Req, 1)
	reqList[0] = req
	request.Req = reqList
	request.Req_module = "imms"
	request.Server = "mmsda"
	///////////////////////
	//	jsonrequest, _ := json.Marshal(request)
	//	fmt.Println(string(jsonrequest))
	//	content, _ := mcpack.Marshal(request)
	//	fmt.Println(hex.Dump(content))
	//	msg := Request{}
	//	mcpack.Unmarshal(content, &msg)
	//	jsonMsg, _ := json.Marshal(msg)
	//	fmt.Println(string(jsonMsg))
	//return
	/////////////////////
	server := []string{HostAdd}
	client := mcpacknpc.NewClient(server)
	reply := new(Reply)
	now := time.Now()
	nanos := now.UnixNano()
	num := make(chan int, 64)
	for i := 0; i < 300000; i++ {
		num <- i
		go mmsda(client, &request, reply, num)
	}
	end := now.UnixNano()
	fmt.Println("time", (end - nanos))
	//	client.Call(request, reply)
	//	fmt.Println(reply)
	//	jsonother, _ := json.Marshal(reply)
	//	fmt.Println(string(jsonother))
	//	dec := mahonia.NewDecoder("gbk")
	//	fmt.Println(dec.ConvertString(reply.Result[0].Normal.Danormalanalysis.Voiceguidesidentify.Fullreplace_query))
	//fmt.Println(reply.Result[0].Normal.Danormalanalysis.Voiceguidesidentify.Fullreplace_query)

}