github.com/primecitizens/pcz/std@v0.2.1/encoding/binfmt/wasm/utils.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package wasm 5 6 func readU8[T ~uint8 | ~int8](data []byte) (v T, next []byte, ok bool) { 7 if len(data) == 0 { 8 return 9 } 10 11 return T(data[0]), data[1:], true 12 } 13 14 func readU32(data []byte) (v uint32, next []byte, ok bool) { 15 var shift uint32 16 for len(data) > 0 { 17 b := data[0] 18 data = data[1:] 19 20 v |= uint32(b&0x7F) << shift 21 if (b & 0x80) == 0 { 22 ok = true 23 break 24 } 25 shift += 7 26 } 27 28 next = data 29 return 30 }