github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/syllab/decode-unsafe.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package syllab 4 5 import "../convert" 6 7 /* 8 ************************************************************************************************** 9 *****************************************Fixed Size ARRAY***************************************** 10 ************************************************************************************************** 11 */ 12 13 // Unsafe don't give any efficient in fixed size data! Use decode safe functions! 14 15 /* 16 ************************************************************************************************** 17 **************************************Dynamically size ARRAY************************************** 18 ************************************************************************************************** 19 */ 20 21 // UnsafeGetString decodes string from the payload buffer in unsafe manner! 22 func UnsafeGetString(p []byte, stackIndex uint32) string { 23 var add uint32 = GetUInt32(p, stackIndex) 24 var ln uint32 = GetUInt32(p, stackIndex+4) 25 return convert.UnsafeByteSliceToString(p[add : add+ln]) 26 } 27 28 // UnsafeGetByteArray decodes byte slice from the payload buffer in unsafe manner! 29 func UnsafeGetByteArray(p []byte, stackIndex uint32) []byte { 30 var add uint32 = GetUInt32(p, stackIndex) 31 var ln uint32 = GetUInt32(p, stackIndex+4) 32 return p[add : add+ln] 33 } 34 35 // UnsafeGetInt8Array decodes int8 slice from the payload buffer in unsafe manner! 36 func UnsafeGetInt8Array(p []byte, stackIndex uint32) []int8 { 37 var add uint32 = GetUInt32(p, stackIndex) 38 var ln uint32 = GetUInt32(p, stackIndex+4) 39 return convert.UnsafeByteSliceToInt8Slice(p[add : add+ln]) 40 } 41 42 // UnsafeGetBoolArray decodes bool array from the payload buffer! 43 func UnsafeGetBoolArray(p []byte, stackIndex uint32) (slice []bool) { 44 var add uint32 = GetUInt32(p, stackIndex) 45 var ln uint32 = GetUInt32(p, stackIndex+4) 46 return convert.UnsafeByteSliceToBoolSlice(p[add : add+ln]) 47 } 48 49 // UnsafeGetInt16Array decode Int16 array from the payload buffer 50 func UnsafeGetInt16Array(p []byte, stackIndex uint32) (slice []int16) { 51 var add uint32 = GetUInt32(p, stackIndex) 52 var ln uint32 = GetUInt32(p, stackIndex+4) 53 return convert.UnsafeByteSliceToInt16Slice(p[add : add+(ln*2)]) 54 } 55 56 // UnsafeGetUInt16Array decode UInt16 array from the payload buffer 57 func UnsafeGetUInt16Array(p []byte, stackIndex uint32) (slice []uint16) { 58 var add uint32 = GetUInt32(p, stackIndex) 59 var ln uint32 = GetUInt32(p, stackIndex+4) 60 return convert.UnsafeByteSliceToUInt16Slice(p[add : add+(ln*2)]) 61 } 62 63 // UnsafeGetInt32Array decode fixed size Int32 array from the payload buffer 64 func UnsafeGetInt32Array(p []byte, stackIndex uint32) (slice []int32) { 65 var add uint32 = GetUInt32(p, stackIndex) 66 var ln uint32 = GetUInt32(p, stackIndex+4) 67 return convert.UnsafeByteSliceToInt32Slice(p[add : add+(ln*4)]) 68 } 69 70 // UnsafeGetUInt32Array decode fixed size UInt32 array from the payload buffer 71 func UnsafeGetUInt32Array(p []byte, stackIndex uint32) (slice []uint32) { 72 var add uint32 = GetUInt32(p, stackIndex) 73 var ln uint32 = GetUInt32(p, stackIndex+4) 74 return convert.UnsafeByteSliceToUInt32Slice(p[add : add+(ln*4)]) 75 } 76 77 // UnsafeGetInt64Array decode fixed size Int64 array from the payload buffer 78 func UnsafeGetInt64Array(p []byte, stackIndex uint32) (slice []int64) { 79 var add uint32 = GetUInt32(p, stackIndex) 80 var ln uint32 = GetUInt32(p, stackIndex+4) 81 return convert.UnsafeByteSliceToInt64Slice(p[add : add+(ln*8)]) 82 } 83 84 // UnsafeGetUInt64Array decode fixed size UInt64 array from the payload buffer 85 func UnsafeGetUInt64Array(p []byte, stackIndex uint32) (slice []uint64) { 86 var add uint32 = GetUInt32(p, stackIndex) 87 var ln uint32 = GetUInt32(p, stackIndex+4) 88 return convert.UnsafeByteSliceToUInt64Slice(p[add : add+(ln*8)]) 89 } 90 91 // UnsafeGetFloat32Array decode fixed size Float32 array from the payload buffer 92 func UnsafeGetFloat32Array(p []byte, stackIndex uint32) (slice []float32) { 93 var add uint32 = GetUInt32(p, stackIndex) 94 var ln uint32 = GetUInt32(p, stackIndex+4) 95 return convert.UnsafeByteSliceToFloat32Slice(p[add : add+(ln*4)]) 96 } 97 98 // UnsafeGetFloat64Array decode fixed size Float64 array from the payload buffer 99 func UnsafeGetFloat64Array(p []byte, stackIndex uint32) (slice []float64) { 100 var add uint32 = GetUInt32(p, stackIndex) 101 var ln uint32 = GetUInt32(p, stackIndex+4) 102 return convert.UnsafeByteSliceToFloat64Slice(p[add : add+(ln*8)]) 103 } 104 105 // UnsafeGetComplex64Array decode fixed size Complex64 array from the payload buffer 106 func UnsafeGetComplex64Array(p []byte, stackIndex uint32) (slice []complex64) { 107 var add uint32 = GetUInt32(p, stackIndex) 108 var ln uint32 = GetUInt32(p, stackIndex+4) 109 return convert.UnsafeByteSliceToComplex64Slice(p[add : add+(ln*8)]) 110 } 111 112 // UnsafeGetComplex128Array decode fixed size Complex128 array from the payload buffer 113 func UnsafeGetComplex128Array(p []byte, stackIndex uint32) (slice []complex128) { 114 var add uint32 = GetUInt32(p, stackIndex) 115 var ln uint32 = GetUInt32(p, stackIndex+4) 116 return convert.UnsafeByteSliceToComplex128Slice(p[add : add+(ln*16)]) 117 } 118 119 /* 120 ************************************************************************************************** 121 *******************Dynamically size ARRAY inside other Dynamically size Array******************* 122 ************************************************************************************************** 123 */ 124 125 // UnsafeGetStringArray encode string array to the payload buffer! 126 func UnsafeGetStringArray(p []byte, stackIndex uint32) (slice []string) { 127 var add uint32 = GetUInt32(p, stackIndex) 128 var ln uint32 = GetUInt32(p, stackIndex+4) 129 slice = make([]string, ln) 130 131 for i := 0; i < int(ln); i++ { 132 var eachAdd uint32 = GetUInt32(p, add) 133 var eachLn uint32 = GetUInt32(p, add+4) 134 slice[i] = convert.UnsafeByteSliceToString(p[eachAdd : eachAdd+eachLn]) 135 add += 8 136 } 137 return 138 }