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

Function WriteMessage

p2pserver/message/types/message.go:90–106  ·  view source on GitHub ↗
(sink *comm.ZeroCopySink, msg Message)

Source from the content-addressed store, hash-verified

88}
89
90func WriteMessage(sink *comm.ZeroCopySink, msg Message) {
91 pstart := sink.Size()
92 sink.NextBytes(common.MSG_HDR_LEN) // can not save the buf, since it may reallocate in sink
93 msg.Serialization(sink)
94 pend := sink.Size()
95 total := pend - pstart
96 payLen := total - common.MSG_HDR_LEN
97
98 sink.BackUp(total)
99 buf := sink.NextBytes(total)
100 checksum := common.Checksum(buf[common.MSG_HDR_LEN:])
101 hdr := newMessageHeader(msg.CmdType(), uint32(payLen), checksum)
102
103 sink.BackUp(total)
104 writeMessageHeaderInto(sink, hdr)
105 sink.NextBytes(payLen)
106}
107
108func ReadMessage(reader io.Reader) (Message, uint32, error) {
109 hdr, err := readMessageHeader(reader)

Callers 4

SendMethod · 0.92
BroadcastMethod · 0.92
SendMethod · 0.92
MessageTestFunction · 0.85

Calls 8

ChecksumFunction · 0.92
newMessageHeaderFunction · 0.85
writeMessageHeaderIntoFunction · 0.85
SerializationMethod · 0.65
CmdTypeMethod · 0.65
SizeMethod · 0.45
NextBytesMethod · 0.45
BackUpMethod · 0.45

Tested by 1

MessageTestFunction · 0.68