github.com/15mga/kiwi@v0.0.2-0.20240324021231-b95d5c3ac751/util/gob.go (about) 1 package util 2 3 import ( 4 "encoding/gob" 5 ) 6 7 func GobMarshal(v any) ([]byte, error) { 8 var buffer ByteBuffer 9 buffer.InitCap(128) 10 err := gob.NewEncoder(&buffer).Encode(v) 11 if err != nil { 12 return nil, err 13 } 14 return buffer.All(), nil 15 } 16 17 func GobUnmarshal(data []byte, v any) error { 18 var buffer ByteBuffer 19 buffer.InitBytes(data) 20 return gob.NewDecoder(&buffer).Decode(v) 21 }