github.com/yimialmonte/fabric@v2.1.1+incompatible/common/tools/protolator/protoext/decorate.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package protoext
     8  
     9  import (
    10  	"github.com/golang/protobuf/proto"
    11  	"github.com/hyperledger/fabric-protos-go/common"
    12  	"github.com/hyperledger/fabric-protos-go/ledger/rwset"
    13  	"github.com/hyperledger/fabric-protos-go/msp"
    14  	"github.com/hyperledger/fabric-protos-go/orderer"
    15  	"github.com/hyperledger/fabric-protos-go/peer"
    16  	"github.com/hyperledger/fabric/common/tools/protolator/protoext/commonext"
    17  	"github.com/hyperledger/fabric/common/tools/protolator/protoext/ledger/rwsetext"
    18  	"github.com/hyperledger/fabric/common/tools/protolator/protoext/mspext"
    19  	"github.com/hyperledger/fabric/common/tools/protolator/protoext/ordererext"
    20  	"github.com/hyperledger/fabric/common/tools/protolator/protoext/peerext"
    21  )
    22  
    23  // Docorate will add additional capabilities to some protobuf messages that
    24  // enable proper JSON marshalling and unmarshalling in protolator.
    25  func Decorate(msg proto.Message) proto.Message {
    26  	switch m := msg.(type) {
    27  	case *common.BlockData:
    28  		return &commonext.BlockData{BlockData: m}
    29  	case *common.Config:
    30  		return &commonext.Config{Config: m}
    31  	case *common.ConfigSignature:
    32  		return &commonext.ConfigSignature{ConfigSignature: m}
    33  	case *common.ConfigUpdate:
    34  		return &commonext.ConfigUpdate{ConfigUpdate: m}
    35  	case *common.ConfigUpdateEnvelope:
    36  		return &commonext.ConfigUpdateEnvelope{ConfigUpdateEnvelope: m}
    37  	case *common.Envelope:
    38  		return &commonext.Envelope{Envelope: m}
    39  	case *common.Header:
    40  		return &commonext.Header{Header: m}
    41  	case *common.ChannelHeader:
    42  		return &commonext.ChannelHeader{ChannelHeader: m}
    43  	case *common.SignatureHeader:
    44  		return &commonext.SignatureHeader{SignatureHeader: m}
    45  	case *common.Payload:
    46  		return &commonext.Payload{Payload: m}
    47  	case *common.Policy:
    48  		return &commonext.Policy{Policy: m}
    49  
    50  	case *msp.MSPConfig:
    51  		return &mspext.MSPConfig{MSPConfig: m}
    52  	case *msp.MSPPrincipal:
    53  		return &mspext.MSPPrincipal{MSPPrincipal: m}
    54  
    55  	case *orderer.ConsensusType:
    56  		return &ordererext.ConsensusType{ConsensusType: m}
    57  
    58  	case *peer.ChaincodeAction:
    59  		return &peerext.ChaincodeAction{ChaincodeAction: m}
    60  	case *peer.ChaincodeActionPayload:
    61  		return &peerext.ChaincodeActionPayload{ChaincodeActionPayload: m}
    62  	case *peer.ChaincodeEndorsedAction:
    63  		return &peerext.ChaincodeEndorsedAction{ChaincodeEndorsedAction: m}
    64  	case *peer.ChaincodeProposalPayload:
    65  		return &peerext.ChaincodeProposalPayload{ChaincodeProposalPayload: m}
    66  	case *peer.ProposalResponsePayload:
    67  		return &peerext.ProposalResponsePayload{ProposalResponsePayload: m}
    68  	case *peer.TransactionAction:
    69  		return &peerext.TransactionAction{TransactionAction: m}
    70  
    71  	case *rwset.TxReadWriteSet:
    72  		return &rwsetext.TxReadWriteSet{TxReadWriteSet: m}
    73  
    74  	default:
    75  		return msg
    76  	}
    77  }