MCPcopy Create free account
hub / github.com/DNAProject/DNA / DeserializeVbftMsg

Function DeserializeVbftMsg

consensus/vbft/msg_builder.go:44–124  ·  view source on GitHub ↗
(msgPayload []byte)

Source from the content-addressed store, hash-verified

42}
43
44func DeserializeVbftMsg(msgPayload []byte) (ConsensusMsg, error) {
45
46 m := &ConsensusMsgPayload{}
47 if err := json.Unmarshal(msgPayload, m); err != nil {
48 return nil, fmt.Errorf("unmarshal consensus msg payload: %s", err)
49 }
50 if m.Len < uint32(len(m.Payload)) {
51 return nil, fmt.Errorf("invalid payload length: %d", m.Len)
52 }
53
54 switch m.Type {
55 case BlockProposalMessage:
56 t := &blockProposalMsg{}
57 if err := t.UnmarshalJSON(m.Payload); err != nil {
58 return nil, fmt.Errorf("failed to unmarshal msg (type: %d): %s", m.Type, err)
59 }
60 return t, nil
61 case BlockEndorseMessage:
62 t := &blockEndorseMsg{}
63 if err := json.Unmarshal(m.Payload, t); err != nil {
64 return nil, fmt.Errorf("failed to unmarshal msg (type: %d): %s", m.Type, err)
65 }
66 return t, nil
67 case BlockCommitMessage:
68 t := &blockCommitMsg{}
69 if err := json.Unmarshal(m.Payload, t); err != nil {
70 return nil, fmt.Errorf("failed to unmarshal msg (type: %d): %s", m.Type, err)
71 }
72 return t, nil
73 case PeerHandshakeMessage:
74 t := &peerHandshakeMsg{}
75 if err := json.Unmarshal(m.Payload, t); err != nil {
76 return nil, fmt.Errorf("failed to unmarshal msg (type: %d): %s", m.Type, err)
77 }
78 return t, nil
79 case PeerHeartbeatMessage:
80 t := &peerHeartbeatMsg{}
81 if err := json.Unmarshal(m.Payload, t); err != nil {
82 return nil, fmt.Errorf("failed to unmarshal msg (type: %d): %s", m.Type, err)
83 }
84 return t, nil
85 case BlockInfoFetchMessage:
86 t := &BlockInfoFetchMsg{}
87 if err := json.Unmarshal(m.Payload, t); err != nil {
88 return nil, fmt.Errorf("failed to unmarshal msg (type: %d): %s", m.Type, err)
89 }
90 return t, nil
91 case BlockInfoFetchRespMessage:
92 t := &BlockInfoFetchRespMsg{}
93 if err := json.Unmarshal(m.Payload, t); err != nil {
94 return nil, fmt.Errorf("failed to unmarshal msg (type: %d): %s", m.Type, err)
95 }
96 return t, nil
97 case BlockFetchMessage:
98 t := &blockFetchMsg{}
99 if err := json.Unmarshal(m.Payload, t); err != nil {
100 return nil, fmt.Errorf("failed to unmarshal msg (type: %d): %s", m.Type, err)
101 }

Callers 2

TestDeserializeVbftMsgFunction · 0.85
runMethod · 0.85

Calls 3

ErrorfMethod · 0.80
DeserializeMethod · 0.65
UnmarshalJSONMethod · 0.45

Tested by 1

TestDeserializeVbftMsgFunction · 0.68