github.com/clubpay/ronykit/kit@v0.14.4-0.20240515065620-d0dace45cbc7/utils/str.go (about) 1 package utils 2 3 import ( 4 "encoding/binary" 5 "strings" 6 ) 7 8 func CloneStr(s string) string { 9 return string(S2B(s)) 10 } 11 12 func CloneBytes(b []byte) []byte { 13 return []byte(B2S(b)) 14 } 15 16 /* 17 Strings Builder helper functions 18 */ 19 20 func AppendStrInt(sb *strings.Builder, x int) { 21 var b [8]byte 22 23 binary.BigEndian.PutUint64(b[:], uint64(x)) 24 sb.Write(b[:]) 25 } 26 27 func AppendStrUInt(sb *strings.Builder, x uint) { 28 var b [8]byte 29 30 binary.BigEndian.PutUint64(b[:], uint64(x)) 31 sb.Write(b[:]) 32 } 33 34 func AppendStrInt64(sb *strings.Builder, x int64) { 35 var b [8]byte 36 37 binary.BigEndian.PutUint64(b[:], uint64(x)) 38 sb.Write(b[:]) 39 } 40 41 func AppendStrUInt64(sb *strings.Builder, x uint64) { 42 var b [8]byte 43 44 binary.BigEndian.PutUint64(b[:], x) 45 sb.Write(b[:]) 46 } 47 48 func AppendStrInt32(sb *strings.Builder, x int32) { 49 var b [4]byte 50 binary.BigEndian.PutUint32(b[:], uint32(x)) 51 sb.Write(b[:]) 52 } 53 54 func AppendStrUInt32(sb *strings.Builder, x uint32) { 55 var b [4]byte 56 binary.BigEndian.PutUint32(b[:], x) 57 sb.Write(b[:]) 58 }