INNER CODE UNIT · Go
bufPtr
krypton-byte/neonize · goneonize/main.go:391
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
// zero-value struct — the same as a successful call with no data.
return (*C.struct_BytesReturn)(C.calloc(1, C.size_t(unsafe.Sizeof(C.struct_BytesReturn{}))))
}
result := (*C.struct_BytesReturn)(C.malloc(C.size_t(unsafe.Sizeof(C.struct_BytesReturn{}))))
result.size = C.size_t(len(data_buf))
if len(data_buf) > 0 {
result.data = (*C.char)(C.malloc(result.size))
C.memcpy(unsafe.Pointer(result.data), unsafe.Pointer(&data_buf[0]), result.size)
} else {
result.data = nil
}
*bufPtr = data_buf // keep the grown capacity for the next caller