github.com/Finschia/ostracon@v1.1.5/proto/ostracon/blockchain/message.go (about)

     1  package blockchain
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/gogo/protobuf/proto"
     7  	"github.com/tendermint/tendermint/p2p"
     8  )
     9  
    10  var _ p2p.Wrapper = &BlockResponse{}
    11  
    12  func (m *BlockResponse) Wrap() proto.Message {
    13  	bm := &Message{}
    14  	bm.Sum = &Message_BlockResponse{BlockResponse: m}
    15  	return bm
    16  }
    17  
    18  // Unwrap implements the p2p Wrapper interface and unwraps a wrapped blockchain
    19  // message.
    20  func (m *Message) Unwrap() (proto.Message, error) {
    21  	switch msg := m.Sum.(type) {
    22  	case *Message_BlockRequest:
    23  		return m.GetBlockRequest(), nil
    24  
    25  	case *Message_BlockResponse:
    26  		return m.GetBlockResponse(), nil
    27  
    28  	case *Message_NoBlockResponse:
    29  		return m.GetNoBlockResponse(), nil
    30  
    31  	case *Message_StatusRequest:
    32  		return m.GetStatusRequest(), nil
    33  
    34  	case *Message_StatusResponse:
    35  		return m.GetStatusResponse(), nil
    36  
    37  	default:
    38  		return nil, fmt.Errorf("unknown message: %T", msg)
    39  	}
    40  }