本文整理匯總了Golang中utility/base.Proto.ReadBinaryProto方法的典型用法代碼示例。如果您正苦於以下問題:Golang Proto.ReadBinaryProto方法的具體用法?Golang Proto.ReadBinaryProto怎麽用?Golang Proto.ReadBinaryProto使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類utility/base.Proto
的用法示例。
在下文中一共展示了Proto.ReadBinaryProto方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: readTask
func (pu *PUDevice) readTask() {
defer func() {
if r := recover(); r != nil {
mylog.GetErrorLogger().Println("readTask panic")
return
}
}()
for {
proto := new(base.Proto)
err := proto.ReadBinaryProto(pu.connSocket)
if err != nil {
pu.handleError(err)
break
}
cmdID := proto.RD.BaseHD.CommandId & 0x7f
if cmdID == base.HEART_CMD {
mylog.GetErrorLogger().Println("Recv And Send Heart", proto.RD.BaseHD.CommandId)
heartProto := new(base.Proto)
heartProto.RD.BaseHD.CommandId = 0x80 | cmdID
pu.rwChan <- heartProto
} else {
mylog.GetErrorLogger().Println(string(proto.BD.Data[4:]))
if cmdID == base.OPEN_RESOURCE_CMD {
go pu.openSource(proto.RD.HD.ClientIdent)
} else if cmdID == base.CLOSE_RESOURCE_CMD {
go pu.closeSource(proto.RD.HD.ClientIdent)
} else if cmdID == base.REGISTER_RESOURCE {
var reponseJson base.ResponseJson
resErr := json.Unmarshal(proto.BD.Data[4:], &reponseJson)
if resErr != nil {
pu.handleError(resErr)
return
}
if reponseJson.Error != base.OK {
pu.handleError(base.DTerror{"Resoure Fail"})
fmt.Println(reponseJson.Error)
return
}
stat.GetLocalStatistInst().RegisterRes()
}
}
}
}
示例2: readTask
func (cu *CUClient) readTask() {
defer func() {
if r := recover(); r != nil {
cu.handleError(base.DTerror{})
}
}()
for {
proto := new(base.Proto)
err := proto.ReadBinaryProto(cu.connSocket)
if err != nil {
cu.handleError(err)
return
}
cmdID := proto.RD.BaseHD.CommandId & 0x7f
//fmt.Println("Recv CommandID ", cmdID)
if cmdID == base.HEART_CMD {
isRequest := proto.RD.BaseHD.CommandId & 0x80
if isRequest == 0 {
heartHdr := new(base.BaseHeader)
heartHdr.CommandId = proto.RD.BaseHD.CommandId | 0x80
msg := heartHdr.Encode()
_, err := cu.connSocket.Write(msg.Bytes())
if err != nil {
cu.handleError(base.DTerror{"Send Error " + err.Error()})
}
//fmt.Println("Send Heart")
} else {
cu.heartChn <- true
//fmt.Println("Recv Heart")
}
} else if cmdID == base.DATA_STREAM {
// stat.GetLocalStatistInst().RecvData(uint64(proto.RD.HD.BodyLen))
var frameType uint16 = 0
var err error = nil
err = binary.Read(bytes.NewBuffer(proto.BD.Data[10:12]), binary.LittleEndian, &frameType)
if err != nil {
fmt.Println(err)
}
// 由於我們公司的h264數據的sps中video_format沒有指定yuv格式
// 所以在這裏直接指定為2,即yuv420p
if frameType == 1 {
cu.frameCount++
}
if cu.frameCount == 1 {
//proto.BD.Data[32] = 0x5D
proto.BD.Data[42] = 0x90
result := frameRateChange(proto.BD.Data[33:38])
for i := 0; i < 5; i++ {
proto.BD.Data[33+i] = result[i]
}
backSPS := bytes.NewBuffer(proto.BD.Data[20:])
if cu.ffmpegChn != nil {
cu.ffmpegChn.Write(backSPS.Bytes())
} else if cu.hlsHandler != nil {
cu.hlsHandler.Write(backSPS.Bytes())
} else if cu.debugChn != nil {
cu.debugChn.Write(backSPS.Bytes())
}
continue
} else if cu.frameCount == 3 {
cu.frameCount = 0
}
if cu.ffmpegChn != nil {
cu.ffmpegChn.Write(proto.BD.Data[20:])
} else if cu.hlsHandler != nil {
cu.hlsHandler.Write(proto.BD.Data[20:])
} else if cu.debugChn != nil {
cu.debugChn.Write(proto.BD.Data[20:])
}
} else if cmdID == base.OPEN_RESOURCE_CMD {
var responseJson base.ResponseJson
fmt.Println("Open Response :", string(proto.BD.Data[4:]))
unerr := json.Unmarshal(proto.BD.Data[4:], &responseJson)
if unerr != nil {
cu.handleError(unerr)
break
}
if !bytes.Equal([]byte("ok"), []byte(responseJson.Error)) {
cu.handleError(unerr)
break
}
//stat.GetLocalStatistInst().OpenRes()
} else if cmdID == base.CLOSE_RESOURCE_CMD {
var responseJson base.ResponseJson
//stat.GetLocalStatistInst().CloseRes()
fmt.Println("Close Response :", string(proto.BD.Data[4:]))
unerr := json.Unmarshal(proto.BD.Data[4:], &responseJson)
if unerr != nil {
//.........這裏部分代碼省略.........