本文整理汇总了Golang中utility/base.Proto.EncodeHdr方法的典型用法代码示例。如果您正苦于以下问题:Golang Proto.EncodeHdr方法的具体用法?Golang Proto.EncodeHdr怎么用?Golang Proto.EncodeHdr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utility/base.Proto
的用法示例。
在下文中一共展示了Proto.EncodeHdr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例2: handleWriteSocket
func (chn *Channel) handleWriteSocket(proto *base.Proto) {
if atomic.CompareAndSwapUint32(&chn.valid, 0, 0) {
return
}
cmdID := proto.RD.BaseHD.CommandId & 0x7f
if cmdID == base.HEART_CMD {
heartHdr := new(base.BaseHeader)
heartHdr.CommandId = proto.RD.BaseHD.CommandId
msg := heartHdr.Encode()
_, err := chn.connSocket.Write(msg.Bytes())
if err != nil {
chn.handleError(base.DTerror{"Send Error"})
}
return
}
fmt.Println("handleWriteSocket ", cmdID)
msg := proto.EncodeHdr()
_, err := chn.connSocket.Write(msg.Bytes())
if err != nil {
chn.handleError(base.DTerror{"Send Error"})
}
_, dErr := chn.connSocket.Write(proto.BD.Data)
if dErr != nil {
chn.handleError(base.DTerror{"Send Error"})
}
base.PutProto(proto)
}
示例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
}
示例4: handleWriteSocket
func (pu *PUDevice) handleWriteSocket(proto *base.Proto) {
if atomic.CompareAndSwapUint32(&pu.Valid, 0, 0) {
return
}
cmdID := proto.RD.BaseHD.CommandId & 0x7f
if cmdID == base.HEART_CMD {
heartHdr := new(base.BaseHeader)
heartHdr.CommandId = proto.RD.BaseHD.CommandId
msg := heartHdr.Encode()
_, err := pu.connSocket.Write(msg.Bytes())
if err != nil {
pu.handleError(base.DTerror{"Send Error " + err.Error()})
}
return
}
msg := proto.EncodeHdr()
_, err := pu.connSocket.Write(msg.Bytes())
if err != nil {
pu.handleError(base.DTerror{"Send Error " + err.Error()})
return
}
_, dErr := pu.connSocket.Write(proto.BD.Data)
if dErr != nil {
pu.handleError(base.DTerror{"Send Error" + err.Error()})
return
}
}