我想将uint8_t数组从C发送到GO,但是当我像指针一样发送数组时,我不知道如何读取它并将其像字节[]数组一样保存在GO中:
package main
/*
#include <stdint.h>
uint8_t Plaintext[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
uint8_t * send_data( )
{
return Plaintext;
}
*/
import "C"
import "unsafe"
import "fmt"
func main() {
data := [16]byte{}
p := C.send_data()
//already try data = C.send_data()
fmt.Println(p)
data = p // don't know how do this ?
}
objectif将具有数据字节数组,例如:
data[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}
我尝试了很多解决方案,但是每次我有日志说“不能使用(func文字)()(类型* _Ctype_uchar)作为类型” uint8”或“字节” ...
谢谢大家的帮助!
我想将uint8_t数组从C发送到Go
package main
/*
#include <stdint.h>
uint8_t Plaintext[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
uint8_t *send_data( ) {
return Plaintext;
}
*/
import "C"
import (
"fmt"
"unsafe"
)
func main() {
data := (*[16]byte)(unsafe.Pointer(C.send_data()))
fmt.Println(*data)
}
输出:[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]