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


Golang IMsg.UnmarshalBinary方法代码示例

本文整理汇总了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

}
开发者ID:jjdevbiz,项目名称:factomd,代码行数:54,代码来源:general.go


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