当前位置: 首页>>代码示例>>Golang>>正文


Golang Proto.EncodeBody方法代码示例

本文整理汇总了Golang中utility/base.Proto.EncodeBody方法的典型用法代码示例。如果您正苦于以下问题:Golang Proto.EncodeBody方法的具体用法?Golang Proto.EncodeBody怎么用?Golang Proto.EncodeBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utility/base.Proto的用法示例。


在下文中一共展示了Proto.EncodeBody方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: closeSource

func (cu *CUClient) closeSource(clientID uint32, id string) {

	var err error
	proto := new(base.Proto)
	proto.RD.BaseHD.CommandId = base.CLOSE_RESOURCE_CMD
	proto.RD.HD.ClientIdent = clientID
	proto.RD.HD.ContextType = base.CONTEXT_JSON
	proto.RD.HD.TransferType = base.TRANSFER_RAW

	resourceJson := base.CloseResParamJson{id}

	requestJson := base.RequestJson{"", "ns", "close", resourceJson}
	b, err := json.Marshal(requestJson)
	if err != nil {
		cu.handleError(err)
		return
	}

	proto.EncodeBody(b)
	result := proto.EncodeHdr()
	n, err := cu.connSocket.Write(result.Bytes())
	if err != nil {
		cu.handleError(err)
		return
	}
	n = n

	_, bErr := cu.connSocket.Write(proto.BD.Data)
	if err != nil {
		cu.handleError(bErr)
	}
	return
}
开发者ID:youxidev,项目名称:HLSWebServer,代码行数:33,代码来源:vcu.go

示例2: closeSource

func (pu *PUDevice) closeSource(clientID uint32) error {
	defer func() {
		if r := recover(); r != nil {
			pu.handleError(base.DTerror{"closeSource Panic"})
		}
	}()
	atomic.CompareAndSwapUint32(&pu.SendFlag, 1, 0)

	proto := new(base.Proto)
	proto.RD.BaseHD.CommandId = 0x80 | base.CLOSE_RESOURCE_CMD
	proto.RD.HD.ClientIdent = clientID
	proto.RD.HD.TransferType = base.TRANSFER_RAW
	proto.RD.HD.ContextType = base.CONTEXT_JSON
	responseJson := base.ResponseJson{"ns", "close", "", "ok"}
	b, err := json.Marshal(responseJson)
	if err != nil {
		pu.handleError(err)
		return err
	}

	proto.EncodeBody(b)
	pu.rwChan <- proto

	stat.GetLocalStatistInst().CloseRes()
	return err
}
开发者ID:youxidev,项目名称:HLSWebServer,代码行数:26,代码来源:vpu.go

示例3: openSource

func (cu *CUClient) openSource(clientID uint32, id string) error {

	proto := new(base.Proto)
	proto.RD.BaseHD.CommandId = base.OPEN_RESOURCE_CMD
	proto.RD.HD.ClientIdent = clientID
	proto.RD.HD.ContextType = base.CONTEXT_JSON
	proto.RD.HD.TransferType = base.TRANSFER_RAW

	resourceJson := base.OpenResParamJson{id, 10}

	requestJson := base.RequestJson{cu.token, "ns", "open", resourceJson}
	b, err := json.Marshal(requestJson)
	if err != nil {
		cu.handleError(err)
		return err
	}

	proto.EncodeBody(b)
	result := proto.EncodeHdr()
	n, err := cu.connSocket.Write(result.Bytes())
	if err != nil {
		cu.handleError(err)
		return err
	}
	n = n

	_, bErr := cu.connSocket.Write(proto.BD.Data)
	if err != nil {
		cu.handleError(bErr)
		return err
	}
	go cu.timerClear()
	return err
}
开发者ID:youxidev,项目名称:HLSWebServer,代码行数:34,代码来源:vcu.go

示例4: openSource

func (pu *PUDevice) openSource(clientID uint32) error {

	proto := new(base.Proto)
	proto.RD.BaseHD.CommandId = 0x80 | base.OPEN_RESOURCE_CMD
	proto.RD.HD.ClientIdent = clientID
	proto.RD.HD.TransferType = base.TRANSFER_RAW
	proto.RD.HD.ContextType = base.CONTEXT_JSON

	//resourceJson := command.ResourceDes{id}

	//res, e := json.Marshal(resourceJson)
	//if e != nil {
	//	return e
	//}
	atomic.CompareAndSwapUint32(&pu.SendFlag, 0, 1)

	responseJson := base.ResponseJson{"ns", "open", "", "ok"}
	b, err := json.Marshal(responseJson)
	if err != nil {
		pu.handleError(err)
		return err
	}

	proto.EncodeBody(b)

	pu.rwChan <- proto

	go pu.handleSource(clientID)
	stat.GetLocalStatistInst().OpenRes()
	return err
}
开发者ID:youxidev,项目名称:HLSWebServer,代码行数:31,代码来源:vpu.go

示例5: handleOtherCMD

func (chn *Channel) handleOtherCMD(proto *base.Proto) {

	cmdID := proto.RD.BaseHD.CommandId
	mylog.GetErrorLogger().Println("handleOtherCMD", cmdID)
	error := base.NOSUPPORT501
	responseJson := base.ResponseJson{"", "", "", error}
	b, err := json.Marshal(responseJson)
	if err != nil {
		mylog.GetErrorLogger().Println("handleOtherCMD : ", err)
	}

	proto.EncodeBody(b)
	chn.Send(proto)
}
开发者ID:youxidev,项目名称:HLSWebServer,代码行数:14,代码来源:channel.go

示例6: handleSource

func (pu *PUDevice) handleSource(clientID uint32) {

	defer func() {
		if r := recover(); r != nil {
			pu.handleError(base.DTerror{"handleSource Panic"})
		}
	}()
	file := new(record.RecordFile)
	resourceFile := new(bytes.Buffer)
	resourceFile.WriteString(oneEnvParam.ResourceDir)
	resourceFile.WriteString("\\")
	resourceFile.WriteString(oneEnvParam.ResourceFile)
	fmt.Println("Open File ", resourceFile)
	if b := file.Open("C:\\1.hmv"); !b {
		return
	}
	defer file.Close()
	file.GetHeader()
	for {
		if !atomic.CompareAndSwapUint32(&pu.SendFlag, 1, 1) {
			break
		}
		if atomic.CompareAndSwapUint32(&pu.Valid, 0, 0) {
			break
		}

		proto := new(base.Proto)
		proto.RD.BaseHD.CommandId = 0x80 | base.DATA_STREAM
		proto.RD.HD.TransferType = base.TRANSFER_RAW
		proto.RD.HD.ContextType = base.CONTEXT_VIDEO
		proto.RD.HD.ClientIdent = clientID

		b := file.GetNextFrame()
		if b == nil {
			file.Seek()
			continue
		}
		proto.EncodeBody(b)
		pu.rwChan <- proto

		stat.GetLocalStatistInst().SendData(uint64(len(proto.BD.Data)))

		time.Sleep(100 * time.Millisecond)

	}
}
开发者ID:youxidev,项目名称:HLSWebServer,代码行数:46,代码来源:vpu.go

示例7: Register

func (pu *PUDevice) Register() {
	// 注册资源
	proto := new(base.Proto)
	proto.RD.BaseHD.CommandId = base.REGISTER_RESOURCE
	proto.RD.HD.TransferType = base.TRANSFER_RAW
	proto.RD.HD.ContextType = base.CONTEXT_JSON

	regsterJson := base.RegisterResParamJson{pu.SN, 1, false}
	requestJson := base.RequestJson{"", "ns", "register", regsterJson}

	b, err := json.Marshal(requestJson)
	if err != nil {
		pu.handleError(err)
		return
	}

	proto.EncodeBody(b)
	pu.rwChan <- proto

}
开发者ID:youxidev,项目名称:HLSWebServer,代码行数:20,代码来源:vpu.go

示例8: handleReqOpenRes

func (chn *Channel) handleReqOpenRes(clientID uint32, data []byte) {

	defer func() {
		if r := recover(); r != nil {
			chn.handleError(base.DTerror{"handleReqOpenResr Panic"})
		}
	}()

	var responseErr string = ""
	var resourcer *Resourcer = nil
	var timeOut uint32 = 20 // 默认超时20s

	request, token, err := chn.getReqParam(clientID, data[4:])
	if err != nil {
		chn.sendProto(clientID,
			base.OPEN_RESOURCE_CMD,
			"", err.Error(),
			"huamail.defualt")
		return
	}

	//获取资源
	param := request.Param.(map[string]interface{})
	openResParam := base.OpenResParamJson{param["resourceid"].(string),
		uint32(param["timeout"].(float64))}

	if chn.CheckResIsOpen(clientID) {
		chn.sendProto(clientID,
			base.OPEN_RESOURCE_CMD,
			"", base.OPEN303,
			"huamail.defualt")
		return
	}

	mylog.GetErrorLogger().Println("Chn Open Resource ID ", openResParam.ID)

	if openResParam.TimeOut < 120 { //当超时时间大于120s,设置超时为默认

		timeOut = openResParam.TimeOut
	}

	for delayWait := uint32(0); delayWait < timeOut; delayWait++ {

		resourcer = GetResourcerByID(openResParam.ID)
		if resourcer != nil {
			break
		}

		time.Sleep(1 * time.Second)
	}

	if resourcer == nil {
		mylog.GetErrorLogger().Println("No Found Source ", openResParam.ID)

		chn.sendProto(clientID, base.OPEN_RESOURCE_CMD, "", base.NOFOUNF404, request.Ns)
		ReleaseResourcer(resourcer)

		return
	}

	clientDataID := new(ResourceClient)
	clientDataID.ClientInf = chn
	clientDataID.ClientID = clientID

	_, responseErr = resourcer.Open(clientDataID, request, token)
	responseJson := base.ResponseJson{request.Ns, request.Method, "", responseErr}
	b, err := json.Marshal(responseJson)
	if err != nil {
		mylog.GetErrorLogger().Println("handleOpenResource : ", err)
		ReleaseResourcer(resourcer)
		return
	}

	proto := new(base.Proto)
	proto.RD.BaseHD.CommandId = 0x80 | base.OPEN_RESOURCE_CMD
	proto.RD.HD.ClientIdent = clientID

	proto.EncodeBody(b)

	if !chn.Send(proto) {
		ReleaseResourcer(resourcer)
		return
	}

	if !strings.EqualFold(responseErr, base.OK) {
		ReleaseResourcer(resourcer)
		return
	}

	{
		chn.resMutex.Lock()
		defer chn.resMutex.Unlock()
		chn.openRes[clientID] = resourcer
	}
	stat.GetLocalStatistInst().OpenRes()

}
开发者ID:youxidev,项目名称:HLSWebServer,代码行数:97,代码来源:channel.go


注:本文中的utility/base.Proto.EncodeBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。