本文整理汇总了Golang中github.com/FactomProject/factomd/common/interfaces.IMsg.UnmarshalBinary方法的典型用法代码示例。如果您正苦于以下问题:Golang IMsg.UnmarshalBinary方法的具体用法?Golang IMsg.UnmarshalBinary怎么用?Golang IMsg.UnmarshalBinary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/FactomProject/factomd/common/interfaces.IMsg
的用法示例。
在下文中一共展示了IMsg.UnmarshalBinary方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UnmarshalMessage
func UnmarshalMessage(data []byte) (interfaces.IMsg, error) {
if data == nil {
return nil, fmt.Errorf("No data provided")
}
if len(data) == 0 {
return nil, fmt.Errorf("No data provided")
}
messageType := int(data[0])
var msg interfaces.IMsg
switch messageType {
case constants.EOM_MSG:
msg = new(EOM)
case constants.ACK_MSG:
msg = new(Ack)
case constants.AUDIT_SERVER_FAULT_MSG:
msg = new(AuditServerFault)
case constants.COMMIT_CHAIN_MSG:
msg = new(CommitChainMsg)
case constants.COMMIT_ENTRY_MSG:
msg = new(CommitEntryMsg)
case constants.DIRECTORY_BLOCK_SIGNATURE_MSG:
msg = NewDirectoryBlockSignature()
case constants.EOM_TIMEOUT_MSG:
msg = new(EOMTimeout)
case constants.FACTOID_TRANSACTION_MSG:
msg = new(FactoidTransaction)
case constants.HEARTBEAT_MSG:
msg = new(Heartbeat)
case constants.INVALID_ACK_MSG:
msg = new(InvalidAck)
case constants.INVALID_DIRECTORY_BLOCK_MSG:
msg = new(InvalidDirectoryBlock)
case constants.MISSING_ACK_MSG:
msg = new(MissingAck)
case constants.PROMOTION_DEMOTION_MSG:
msg = new(PromotionDemotion)
case constants.REVEAL_ENTRY_MSG:
msg = new(RevealEntryMsg)
case constants.REQUEST_BLOCK_MSG:
msg = new(RequestBlock)
case constants.SIGNATURE_TIMEOUT_MSG:
msg = new(SignatureTimeout)
default:
return nil, fmt.Errorf("Unknown message type")
}
// Unmarshal does not include the message type.
err := msg.UnmarshalBinary(data[:])
if err != nil {
return nil, err
}
return msg, nil
}