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

Function readMessageHeader

p2pserver/message/types/message.go:56–72  ·  view source on GitHub ↗
(reader io.Reader)

Source from the content-addressed store, hash-verified

54}
55
56func readMessageHeader(reader io.Reader) (messageHeader, error) {
57 msgh := messageHeader{}
58 hdrBytes := make([]byte, comm.UINT32_SIZE+common.MSG_CMD_LEN+comm.UINT32_SIZE+common.CHECKSUM_LEN)
59
60 if _, err := io.ReadFull(reader, hdrBytes); err != nil {
61 return msgh, err
62 }
63
64 source := comm.NewZeroCopySource(hdrBytes)
65 msgh.Magic, _ = source.NextUint32()
66 cmd, _ := source.NextBytes(common.MSG_CMD_LEN)
67 copy(msgh.CMD[:], cmd)
68 msgh.Length, _ = source.NextUint32()
69 checksum, _ := source.NextBytes(common.CHECKSUM_LEN)
70 copy(msgh.Checksum[:], checksum)
71 return msgh, nil
72}
73
74func writeMessageHeaderInto(sink *comm.ZeroCopySink, msgh messageHeader) {
75 sink.WriteUint32(msgh.Magic)

Callers 4

TestMsgHdr2Function · 0.85
TestMsgHdrDesPerformanceFunction · 0.85
ReadMessageFunction · 0.85

Calls 2

NextUint32Method · 0.95
NextBytesMethod · 0.95

Tested by 3

TestMsgHdr2Function · 0.68
TestMsgHdrDesPerformanceFunction · 0.68