INNER CODE UNIT · Go
ProtoReturnV2
krypton-byte/neonize · goneonize/main.go:379
func ProtoReturnV2(data proto.Message) *C.struct_BytesReturn {
data_buf, err := proto.Marshal(data)
if err != nil {
panic(err)
}
return ReturnBytesV2(data_buf)
}
func ProtoReturnV3(data proto.Message) *C.struct_BytesReturn {
// Marshal into a pooled buffer to avoid a fresh heap allocation on every
// call; the bytes are copied onto the C heap below, so the buffer can be
// returned to the pool immediately afterwards.
bufPtr := bufPool.Get().(*[]byte)
data_buf, err := proto.MarshalOptions{}.MarshalAppend((*bufPtr)[:0], data)
if err != nil {
bufPool.Put(bufPtr)
// Return an empty BytesReturn instead of panicking. The Python side
// will receive an empty protobuf message, which unmarshals as a