func decodeTemplate(packet *Packet, end unsafe.Pointer, size uintptr, remote net.IP) {
	min := uintptr(end) - size
	for uintptr(end) > min {
		headerPtr := unsafe.Pointer(uintptr(end) - sizeOfTemplateRecordHeader)
		tmplRecs := &TemplateRecords{}
		tmplRecs.Header = (*TemplateRecordHeader)(unsafe.Pointer(headerPtr))
		tmplRecs.Packet = packet
		tmplRecs.Records = make([]*TemplateRecord, 0, numPreAllocRecs)
		ptr := unsafe.Pointer(uintptr(headerPtr) - sizeOfTemplateRecordHeader)
		var i uint16
		for i = 0; i < tmplRecs.Header.FieldCount; i++ {
			rec := (*TemplateRecord)(unsafe.Pointer(ptr))
			tmplRecs.Records = append(tmplRecs.Records, rec)
			ptr = unsafe.Pointer(uintptr(ptr) - sizeOfTemplateRecord)
		}
		packet.Templates = append(packet.Templates, tmplRecs)
		end = unsafe.Pointer(uintptr(end) - uintptr(tmplRecs.Header.FieldCount)*sizeOfTemplateRecord - sizeOfTemplateRecordHeader)
	}
}
decodeTemplate decodes a template from `packet`
package ipfix
import (
	"fmt"
	"net"
	"unsafe"
	"github.com/google/tflow2/convert"
)
const (
	numPreAllocRecs = 20
)
const SetIDTemplateMax = 255
const TemplateSetID = 2
func errorIncompatibleVersion(version uint16) error {
	return fmt.Errorf("IPFIX: Incompatible protocol version v%d, only v10 is supported", version)
}
func Decode(raw []byte, remote net.IP) (*Packet, error) {
	data := convert.Reverse(raw)  
	pSize := len(data)
	bufSize := 1500
	buffer := [1500]byte{}
	if pSize > bufSize {
		panic("Buffer too small\n")
	}
	for i := 0; i < pSize; i++ {
		buffer[bufSize-pSize+i] = data[i]
	}
	bufferPtr := unsafe.Pointer(&buffer)
	bufferMinPtr := unsafe.Pointer(uintptr(bufferPtr) + uintptr(bufSize) - uintptr(pSize))
	headerPtr := unsafe.Pointer(uintptr(bufferPtr) + uintptr(bufSize) - uintptr(sizeOfHeader))
	var packet Packet
	packet.Buffer = buffer[:]
	packet.Header = (*Header)(headerPtr)
	if packet.Header.Version != 10 {
		return nil, errorIncompatibleVersion(packet.Header.Version)
	}
	packet.Templates = make([]*TemplateRecords, 0, numPreAllocRecs)
	for uintptr(headerPtr) > uintptr(bufferMinPtr) {
		ptr := unsafe.Pointer(uintptr(headerPtr) - sizeOfSetHeader)
		fls := &Set{
			Header: (*SetHeader)(ptr),
		}
		if fls.Header.SetID == TemplateSetID {
			decodeTemplate(&packet, ptr, uintptr(fls.Header.Length)-sizeOfSetHeader, remote)
		} else if fls.Header.SetID > SetIDTemplateMax {
			decodeData(&packet, ptr, uintptr(fls.Header.Length)-sizeOfSetHeader)
		}
		headerPtr = unsafe.Pointer(uintptr(headerPtr) - uintptr(fls.Header.Length))
	}
	return &packet, nil
}
func decodeData(packet *Packet, headerPtr unsafe.Pointer, size uintptr) {
	flsh := (*SetHeader)(unsafe.Pointer(headerPtr))
	data := unsafe.Pointer(uintptr(headerPtr) - uintptr(flsh.Length))
	fls := &Set{
		Header:  flsh,
		Records: (*(*[1<<31 - 1]byte)(data))[sizeOfSetHeader:flsh.Length],
	}
	packet.FlowSets = append(packet.FlowSets, fls)
}