Open
Bug 722040
Opened 13 years ago
Updated 2 years ago
jsctypes is not able to deal with binary/blob strings
Categories
(Core :: js-ctypes, enhancement)
Tracking
()
UNCONFIRMED
People
(Reporter: emmanuel, Unassigned)
References
(Depends on 1 open bug, Blocks 1 open bug)
Details
I want to use jsctypes in a js protocol component (@mozilla.org/network/protocol;1?name=).
For this reasons I need to deal with binary strings which are coming from the C/C++ code as char** (or ctypes.char.ptr given by address as parameter).
Unfortunately the CData readString() method is unadapted (UTF8 and null terminated assumptions) and there is no method to access quickly the underlying byte buffer. So, I have found no efficient way to access the data.
It would be great to modify readString() to allow that or do build a method like data([length]).
Reporter | ||
Updated•13 years ago
|
Summary: jsctypes is not able to deal with binary/blog strings → jsctypes is not able to deal with binary/blob strings
Comment 1•13 years ago
|
||
I need something along these lines for reading Unicode from files by chunks. Emmanuel, what do you think of merging this bug with bug 552551?
Comment 2•12 years ago
|
||
Emmanuel, actually, on second thought, I am not sure of how this relates to readString. Doesn't casting your ctypes.char.ptr to an array do what you need?
I have tried to cast the char.ptr to a uint8 array and it still crashes when accessing the individual elements is there no way to get binary data?
Heres my testing code
var teststring = lib.declare("teststring",
ctypes.default_abi, //ctypes.stdcall_abi, // call ABI
ctypes.int64_t, // return type
ctypes.int32_t.ptr, // buffer size
ctypes.char.ptr //ctypes.char.ptr.array() // Buffer
);
var bufferSize = new ctypes.int32_t(10).address();
var buffer = new ctypes.char();
var bufferPtr = buffer.address();
var ret = teststring(bufferSize, bufferPtr);
var hold = ctypes.cast( bufferPtr, ctypes.ArrayType(ctypes.uint8_t, parseInt(bufferSize.contents)).ptr );
console.error("Hold array length: "+hold.contents.length);
var output = "";
for(var i=0; i<bufferSize.contents; i++){
output+=""+hold.contents[i];
}
console.error("Output: "+output);
I can go directly to a Uint8Array with this
var byteArray = new Uint8Array(buffer);
I think I was trying to hard with the ctypes casting lol
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•