func NewPacket(r io.Reader) (p Packet, err error) {
	p.Header, err = NewHeader(r)
	if err != nil {
		return
	}

	if p.Length < 8 {
		err = ErrInvalidLength
		return
	}

	p.Payload = make([]byte, p.Length-8)
	if _, err = r.Read(p.Payload); err != nil {
		return
	}

	if p.Checksum != 0 && p.CalculateChecksum() != p.Checksum {
		err = ErrInvalidChecksum
		return
	}

	return
}
// NewPacket reads a packet from a reader.
NewPacket reads a packet from a reader.
// NewPacket reads a packet from a reader .
func NewPacket(r io.Reader) (p Packet, err error) {
	p.Header, err = NewHeader(r)
	if err != nil {
		return
	}
	if p.Length < 8 {
		err = ErrInvalidLength
		return
	}
	p.Payload = make([]byte, p.Length-8)
	if _, err = r.Read(p.Payload); err != nil {
		return
	}
	if p.Checksum != 0 && p.CalculateChecksum() != p.Checksum {
		err = ErrInvalidChecksum
		return
	}
	return
}
func NewPacket ( r io . Reader ) ( p Packet , err error ) { p . Header , err = NewHeader ( r ) if err != nil { return } if p . Length < 8 { err = ErrInvalidLength return } p . Payload = make ( [ ] byte , p . Length - 8 ) if _ , err = r . Read ( p . Payload ) ; err != nil { return } if p . Checksum != 0 && p . CalculateChecksum ( ) != p . Checksum { err = ErrInvalidChecksum return } return }
NewPacket reads a packet from a reader.
NewPacket reads a packet from a reader .