github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/rootio/encoding/read.go (about) 1 package hep 2 3 import ( 4 "encoding/binary" 5 "unsafe" 6 ) 7 8 func LittleU32(data []byte) uint32 { 9 return binary.LittleEndian.Uint32(data) 10 } 11 12 func BigU32ar(at int, data []byte) uint32 { 13 return uint32(data[at+3]) | uint32(data[at+2])<<8 | uint32(data[at+1])<<16 | uint32(data[at])<<24 14 } 15 16 func BigU32af(at int, data []byte) uint32 { 17 return uint32(data[at])<<24 | uint32(data[at+1])<<16 | uint32(data[at+2])<<8 | uint32(data[at+3]) 18 } 19 20 func LittleU32af(at int, data []byte) uint32 { 21 return uint32(data[at]) | uint32(data[at+1])<<8 | uint32(data[at+2])<<16 | uint32(data[at+3])<<24 22 } 23 24 func LittleU32ar(at int, data []byte) uint32 { 25 return uint32(data[at+3])<<24 | uint32(data[at+2])<<16 | uint32(data[at+1])<<8 | uint32(data[at]) 26 } 27 28 func NativeU32ad(at int, data []byte) uint32 { 29 _ = data[3] 30 return *(*uint32)(unsafe.Pointer(&data[at])) 31 } 32 func NativeU32adu(at int, data []byte) uint32 { 33 return *(*uint32)(unsafe.Pointer(&data[at])) 34 } 35 36 func BigU32(data []byte) uint32 { 37 return binary.BigEndian.Uint32(data) 38 } 39 40 func BigU32sr(data []byte) uint32 { 41 return uint32(data[3]) | uint32(data[2])<<8 | uint32(data[1])<<16 | uint32(data[0])<<24 42 } 43 44 func BigU32sf(data []byte) uint32 { 45 return uint32(data[0])<<24 | uint32(data[1])<<16 | uint32(data[2])<<8 | uint32(data[3]) 46 } 47 48 func LittleU32sf(data []byte) uint32 { 49 return uint32(data[0]) | uint32(data[1])<<8 | uint32(data[2])<<16 | uint32(data[3])<<24 50 } 51 52 func LittleU32sr(data []byte) uint32 { 53 return uint32(data[3])<<24 | uint32(data[2])<<16 | uint32(data[0+1])<<8 | uint32(data[0]) 54 55 } 56 57 func NativeU32sd(data []byte) uint32 { 58 _ = data[3] 59 return *(*uint32)(unsafe.Pointer(&data[0])) 60 } 61 62 func NativeU32sdu(data []byte) uint32 { 63 return *(*uint32)(unsafe.Pointer(&data[0])) 64 }