github.com/trim21/go-phpserialize@v0.0.22-0.20240301204449-2fca0319b3f0/internal/encoder/int.go (about) 1 package encoder 2 3 import ( 4 "strconv" 5 "unsafe" 6 ) 7 8 func encodeInt8(ctx *Ctx, b []byte, p uintptr) ([]byte, error) { 9 value := **(**int8)(unsafe.Pointer(&p)) 10 return appendIntBytes(b, int64(value)), nil 11 } 12 13 func encodeInt16(ctx *Ctx, b []byte, p uintptr) ([]byte, error) { 14 value := **(**int16)(unsafe.Pointer(&p)) 15 return appendIntBytes(b, int64(value)), nil 16 17 } 18 19 func encodeInt32(ctx *Ctx, b []byte, p uintptr) ([]byte, error) { 20 value := **(**int32)(unsafe.Pointer(&p)) 21 return appendIntBytes(b, int64(value)), nil 22 23 } 24 25 func encodeInt64(ctx *Ctx, b []byte, p uintptr) ([]byte, error) { 26 value := **(**int64)(unsafe.Pointer(&p)) 27 return appendIntBytes(b, int64(value)), nil 28 } 29 30 func encodeInt(ctx *Ctx, b []byte, p uintptr) ([]byte, error) { 31 value := **(**int)(unsafe.Pointer(&p)) 32 return appendIntBytes(b, int64(value)), nil 33 } 34 35 func appendIntBytes(b []byte, v int64) []byte { 36 b = append(b, 'i', ':') 37 b = strconv.AppendInt(b, v, 10) 38 39 return append(b, ';') 40 }