I am calling some C code. One of the structs has a field is of type char [1024]
, which Clang.jl
turns into NTuple{1024,UInt8}
. This is a null-terminated C string.
How can I get a String-like thing from this without copying? I see there is String(v::Array{UInt8,1})
or String(v::AbstractArray{UInt8,1})
, but I have a tuple, not an array.
I was able to do
julia> data = (0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x5f, 0x6a, 0x6f, 0x69, 0x6e, 0x74, 0x00, 0x4f)
(0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x5f, 0x6a, 0x6f, 0x69, 0x6e, 0x74, 0x00, 0x4f)
julia> using StaticArrays
julia> String(SArray{Tuple{length(data)}}(data))
"base_chassis_joint\0O"
which possibly does not do any copying (not sure). But it doesn’t interpret the String as null-terminated.
If I could get a pointer to the data, then I can use Cstring
, however the field is an NTuple
, which has immutable semantics. I cannot call pointer_from_objref
on it.