Use buf pool

- eliminate reader function generation
- fix write to closed channel panic
This commit is contained in:
Zoltan Papp
2024-06-09 20:27:40 +02:00
parent 8c70b7d7ff
commit 5e93d117cf
3 changed files with 78 additions and 42 deletions

View File

@ -110,12 +110,13 @@ func MarshalTransportMsg(peerID []byte, payload []byte) []byte {
return msg
}
func UnmarshalTransportPayload(buf []byte) ([]byte, error) {
func UnmarshalTransportMsg(buf []byte) ([]byte, []byte, error) {
headerSize := 1 + IDSize
if len(buf) < headerSize {
return nil, ErrInvalidMessageLength
return nil, nil, ErrInvalidMessageLength
}
return buf[headerSize:], nil
return buf[1:headerSize], buf[headerSize:], nil
}
func UnmarshalTransportID(buf []byte) ([]byte, error) {