C/C++ way of working with these things requires specifying the start and 
end point using pointer arithmetic, which is pretty cumbersome considering 
how often it is needed. I think what Ian said is probably the most complete 
way to deal with it.

But probably you can also do it using the unsafe library, if you can grab 
the length vector from the C/C++ side, convert to an untyped unsafe 
pointer, and then back to array: [length]byte, and you won't have any 
issues from attempting to write past the allocated end of the buffer. Then 
you can use it like a regular slice by using name[:]. Of course if 
performance is critical you may not want to do that as it is likely to 
trigger a copy operation when you didn't mean it.

On Saturday, 1 December 2018 18:39:45 UTC+1, xiang liu wrote:
>
>
>
> Hi:
>
> I am using swig wrap a c++ module , the generated go code is like this:
>
> type  MediaFrame interface {
>      GetLength()  uint   
>      GetData()  (*byte)
> }
>
> I want to convert the *byte  to []byte,  How to do this?
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to