func (b UDP) Encode(u *UDPFields) {
	binary.BigEndian.PutUint16(b[udpSrcPort:], u.SrcPort)
	binary.BigEndian.PutUint16(b[udpDstPort:], u.DstPort)
	binary.BigEndian.PutUint16(b[udpLength:], u.Length)
	binary.BigEndian.PutUint16(b[udpChecksum:], u.Checksum)
}
Encode encodes all the fields of the udp header.
package header
import (
	"encoding/binary"
	tcpip "github.com/brewlin/net-protocol/protocol"
)
const (
	udpSrcPort  = 0
	udpDstPort  = 2
	udpLength   = 4
	udpChecksum = 6
)
type UDPFields struct {
	SrcPort uint16
	DstPort uint16
	Length uint16
	Checksum uint16
}
type UDP []byte
const (
	UDPMinimumSize = 8
	UDPProtocolNumber tcpip.TransportProtocolNumber = 17
)
func (b UDP) SourcePort() uint16 {
	return binary.BigEndian.Uint16(b[udpSrcPort:])
}
func (b UDP) DestinationPort() uint16 {
	return binary.BigEndian.Uint16(b[udpDstPort:])
}
func (b UDP) Length() uint16 {
	return binary.BigEndian.Uint16(b[udpLength:])
}
func (b UDP) Payload() []byte {
	return b[UDPMinimumSize:]
}
func (b UDP) Checksum() uint16 {
	return binary.BigEndian.Uint16(b[udpChecksum:])
}
func (b UDP) SetSourcePort(port uint16) {
	binary.BigEndian.PutUint16(b[udpSrcPort:], port)
}
func (b UDP) SetDestinationPort(port uint16) {
	binary.BigEndian.PutUint16(b[udpDstPort:], port)
}
func (b UDP) SetChecksum(checksum uint16) {
	binary.BigEndian.PutUint16(b[udpChecksum:], checksum)
}
func (b UDP) CalculateChecksum(partialChecksum uint16, totalLen uint16) uint16 {
	tmp := make([]byte, 2)
	binary.BigEndian.PutUint16(tmp, totalLen)
	checksum := Checksum(tmp, partialChecksum)
	return Checksum(b[:UDPMinimumSize], checksum)
}