3 Star 6 Fork 7

Gitee 极速下载 / Hyperledger fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/hyperledger/fabric
克隆/下载
util.go 2.86 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package configtx
import (
"github.com/golang/protobuf/proto"
cb "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"
)
// UnmarshalConfig attempts to unmarshal bytes to a *cb.Config
func UnmarshalConfig(data []byte) (*cb.Config, error) {
config := &cb.Config{}
err := proto.Unmarshal(data, config)
if err != nil {
return nil, err
}
return config, nil
}
// UnmarshalConfigOrPanic attempts to unmarshal bytes to a *cb.Config or panics on error
func UnmarshalConfigOrPanic(data []byte) *cb.Config {
result, err := UnmarshalConfig(data)
if err != nil {
panic(err)
}
return result
}
// UnmarshalConfigUpdate attempts to unmarshal bytes to a *cb.ConfigUpdate
func UnmarshalConfigUpdate(data []byte) (*cb.ConfigUpdate, error) {
configUpdate := &cb.ConfigUpdate{}
err := proto.Unmarshal(data, configUpdate)
if err != nil {
return nil, err
}
return configUpdate, nil
}
// UnmarshalConfigUpdateOrPanic attempts to unmarshal bytes to a *cb.ConfigUpdate or panics on error
func UnmarshalConfigUpdateOrPanic(data []byte) *cb.ConfigUpdate {
result, err := UnmarshalConfigUpdate(data)
if err != nil {
panic(err)
}
return result
}
// UnmarshalConfigUpdateEnvelope attempts to unmarshal bytes to a *cb.ConfigUpdate
func UnmarshalConfigUpdateEnvelope(data []byte) (*cb.ConfigUpdateEnvelope, error) {
configUpdateEnvelope := &cb.ConfigUpdateEnvelope{}
err := proto.Unmarshal(data, configUpdateEnvelope)
if err != nil {
return nil, err
}
return configUpdateEnvelope, nil
}
// UnmarshalConfigUpdateEnvelopeOrPanic attempts to unmarshal bytes to a *cb.ConfigUpdateEnvelope or panics on error
func UnmarshalConfigUpdateEnvelopeOrPanic(data []byte) *cb.ConfigUpdateEnvelope {
result, err := UnmarshalConfigUpdateEnvelope(data)
if err != nil {
panic(err)
}
return result
}
// UnmarshalConfigEnvelope attempts to unmarshal bytes to a *cb.ConfigEnvelope
func UnmarshalConfigEnvelope(data []byte) (*cb.ConfigEnvelope, error) {
configEnv := &cb.ConfigEnvelope{}
err := proto.Unmarshal(data, configEnv)
if err != nil {
return nil, err
}
return configEnv, nil
}
// UnmarshalConfigEnvelopeOrPanic attempts to unmarshal bytes to a *cb.ConfigEnvelope or panics on error
func UnmarshalConfigEnvelopeOrPanic(data []byte) *cb.ConfigEnvelope {
result, err := UnmarshalConfigEnvelope(data)
if err != nil {
panic(err)
}
return result
}
// UnmarshalConfigUpdateFromPayload unmarshals configuration update from given payload
func UnmarshalConfigUpdateFromPayload(payload *cb.Payload) (*cb.ConfigUpdate, error) {
configEnv, err := UnmarshalConfigEnvelope(payload.Data)
if err != nil {
return nil, err
}
configUpdateEnv, err := utils.EnvelopeToConfigUpdate(configEnv.LastUpdate)
if err != nil {
return nil, err
}
return UnmarshalConfigUpdate(configUpdateEnv.ConfigUpdate)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/fabric.git
git@gitee.com:mirrors/fabric.git
mirrors
fabric
Hyperledger fabric
v1.4.6

搜索帮助

344bd9b3 5694891 D2dac590 5694891