github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/internal/peer/gossip/deserializer.go (about)

     1  /*
     2  Copyright hechain. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package gossip
     8  
     9  import (
    10  	"github.com/hechain20/hechain/msp"
    11  	"github.com/hechain20/hechain/msp/mgmt"
    12  	"github.com/hechain20/hechain/protoutil"
    13  	mspproto "github.com/hyperledger/fabric-protos-go/msp"
    14  )
    15  
    16  // DeserializersManager is a support interface to
    17  // access the local and channel deserializers
    18  type DeserializersManager interface {
    19  
    20  	// Deserialize receives SerializedIdentity bytes and returns the unmarshaled form
    21  	// of the SerializedIdentity, or error on failure
    22  	Deserialize(raw []byte) (*mspproto.SerializedIdentity, error)
    23  
    24  	// GetLocalMSPIdentifier returns the local MSP identifier
    25  	GetLocalMSPIdentifier() string
    26  
    27  	// GetLocalDeserializer returns the local identity deserializer
    28  	GetLocalDeserializer() msp.IdentityDeserializer
    29  
    30  	// GetChannelDeserializers returns a map of the channel deserializers
    31  	GetChannelDeserializers() map[string]msp.IdentityDeserializer
    32  }
    33  
    34  // NewDeserializersManager returns a new instance of DeserializersManager
    35  func NewDeserializersManager(localMSP msp.MSP) DeserializersManager {
    36  	return &mspDeserializersManager{
    37  		localMSP: localMSP,
    38  	}
    39  }
    40  
    41  type mspDeserializersManager struct {
    42  	localMSP msp.MSP
    43  }
    44  
    45  func (m *mspDeserializersManager) Deserialize(raw []byte) (*mspproto.SerializedIdentity, error) {
    46  	return protoutil.UnmarshalSerializedIdentity(raw)
    47  }
    48  
    49  func (m *mspDeserializersManager) GetLocalMSPIdentifier() string {
    50  	id, _ := m.localMSP.GetIdentifier()
    51  	return id
    52  }
    53  
    54  func (m *mspDeserializersManager) GetLocalDeserializer() msp.IdentityDeserializer {
    55  	return m.localMSP
    56  }
    57  
    58  func (m *mspDeserializersManager) GetChannelDeserializers() map[string]msp.IdentityDeserializer {
    59  	return mgmt.GetDeserializers()
    60  }