Use Pascal strings in place of null-termination; update documentation

This commit is contained in:
2026-01-21 18:17:21 -05:00
parent 868db8c038
commit a72be0393c
4 changed files with 99 additions and 20 deletions
+30
View File
@@ -0,0 +1,30 @@
package main
/*
typedef struct {
char* data;
int len;
} PascalString;
*/
import "C"
// getPascalString returns a pascal
// string struct for the input Go string.
func getPascalString(goString string) C.PascalString {
goStringBytes := []byte(goString)
goStringPtr := C.CBytes(goStringBytes)
return C.PascalString{
data: (*C.char)(goStringPtr),
len: C.int(len(goStringBytes)),
}
}
// getPascalStringFromBytes returns a pascal
// string struct for the input Go byte slice.
func getPascalStringFromBytes(goBytes []byte) C.PascalString {
goBytesPtr := C.CBytes(goBytes)
return C.PascalString{
data: (*C.char)(goBytesPtr),
len: C.int(len(goBytes)),
}
}