Append data to an IStream object - visual-c++

I am making calls to a web service to get data from my dll. I am getting the data in a char* object in parts.
I want to get the whole data into an IStream object. I am running a while loop and getting the data into char* object. Can someone please tell me how I can combine all this data into a single IStream or LPSTREAM object.
Thanks
Never got an answer for this one! Can someone please help!

Ok I thought I'd answer this one just to help out. You're making calls to another computer so I'm assuming that you are reading in streams of data in char*'s. That's what I get from a comment like "I am getting the data in a char* object in parts."
Therefore, as I understand it, you just want to append the char* string to the IStream object so that it holds the new data.
My suggestion would be to do this:
Create a streambuf object (http://msdn.microsoft.com/en-us/library/aa277891(VS.60).aspx)
While you are recieving packets
append the packet to the streambuf object (http://msdn.microsoft.com/en-us/library/aa277883(VS.60).aspx)
Create a IStream object and init it with the streambuf object (http://msdn.microsoft.com/en-us/library/aa277365(VS.60).aspx)
Now that should work I think. That will fill your IStream object with the stream you got from the website.
I hope that helps,
Robert

Related

Write float value in Node buffer

I am reading sensor data and I need to send these data via bluetooth so I am using noble/bleno library to subscribe data every time the value change. Here I am confusing how to send data as a buffer.
I have data something like value = 24.3756
So I need to write this in buffer:
let buf = new Buffer(2);
buf.writeIntLE(buf);
But when I convert to ArrayBuffer value shows only 24 (not getting after decimal point)
How to send full float value and read as array buffer ?
First of all please read Buffer documentation here.
Then please don't use deprecated functions. If you need to create a new buffer use Buffer.alloc or Buffer.allocUnsafe. When you're creating buffer ensure that it can hold the data you want to write there. Next please use a suitable method for writing data. You're writing floating point number, then you have to use Buffer.writeFloatBE/Buffer.writeFloatLE. If you do everything I mentioned you'll end up with a correct solution:
const buffer = Buffer.allocUnsafe(4);
buffer.writeFloatLE(24.3756);

How to read an SVG file from stream with MagickNet

My application allows the user to upload images and send them to the service, which then converts it to another format and sends it back. We are adding support for the SVG file format and I am running into an issue with reading the file from a byte array.
The issue is that when I initialize a MagickImageInfo object with the SVG Stream object, I get this error:
"no decode delegate for this image format '' # error/blob.c/BlobToImage/355"
I played around with it and am able to get past this error if I instead create a MagickImage object and supply it with an instance of MagickReadSettings where I set the Format to SVG explicitly.
The core problem is that the MagickImage code needs a hint as to what kind of file it is when it's an SVG. For other file types, it seems to be able to infer what kind of file it is. However, while I am able to supply the MagickImage class with what format the file is, the MagickImageInfo class doesn't have any parameters that I can give it to hint at the file type.
One possible solution would be to write the file to disk, then have MagickImageInfo class read the file from disk, but I really don't want to do this as it adds complexity to the service and makes it depend on disk write access.
Relevant code:
Working code:
var readSettings = new MagickReadSettings() { Format = MagickFormat.Svg };
using (MagickImage image = new MagickImage(stream, readSettings))
{
image.Write("C:\test"); // Actual code doesn't write to disk
}
Not working code:
MagickImageInfo info = new MagickImageInfo(stream);
It appears that you found a missing feature. I found your post here and added an extra overload for the MagickImageInfo constructor. The following will be available in Magick.NET 7.0.3.9 and higher:
var readSettings = new MagickReadSettings() { Format = MagickFormat.Svg };
MagickImageInfo info = new MagickImageInfo(stream, readSettings);
Feel free to open an issue next time here: https://github.com/dlemstra/Magick.NET or here: https://magick.codeplex.com/discussions

Can MessageChannel overflow

I am working on an AS3 project in FDT6. I am using the lastest FLEX 4.6 and AIR 3.7.
I have a worker.swf file that is embedded into the main application to do threading work with.
I am using the MessageChannel class to pass information between the two.
In my main class I have defined
private var mainToWorker:MessageChannel;
private var workerToMain:MessageChannel;
mainToWorker = Worker.current.createMessageChannel(worker);
workerToMain = worker.createMessageChannel(Worker.current);
on the mainToWorker I only ever send messages. In these messages I send a byte array of information. The information is an object that contains a 'command' property and a 'props' property. Basically acting like a function call. The command is a function name and the props is an object that contains data for that function.
mainToWorkerMutex.lock();
mainToWorker.send(ByteArrayUtils.ObjectToByteArray({command:"DoSomething", props:{propA:1,propB:7}}));
mainToWorkerMutex.unlock();
The same occurs for the workerToMain var except I only send byte data that contains the 'message' and 'props' parameters.
workerToMainMutex.lock();
workerToMain.send(ByteArrayUtils.ObjectToByteArray({command:"complete", props:{return:"result"}}));
workerToMainMutex.unlock();
As a sanity check I make sure that the message channels are getting what they should.
It is working fine when I build it in FDT, however when it is built using an ANT script through flash builder I am sometimes getting the 'command' events coming back through in the workerToMain channel.
I am sending quite a lot of data through the message channel. Is it possible that I am overloading it and causing a buffer overflow into the other message channel somehow? How could that only be happening in FB?
I have checked my code many times and I am sure there is nothing in my own code that is sending that message back.
I had similar issue. When sending many bytearrays using channels sometimes things i received was not things i've actually sended. I had 4 channels (message channel to worker, message channel to main, data channel to worker, data channel to main).
I've noticed that data channel to main was affecting message channel to worker. When i turned off data channel to main - message channel to worker stared working just fine :D...
They have a big issue there with sending byte arrays it seems.
But what helped me was using shareable (at first it was not shareable) bytearray for communication via channels, but only for communication, as soon as i am receiving such bytearray i'm copying it to another byte array and parsing a copy.
This removed the problem (made quite hard stress tests there)...
Cheers
P.S. I'm also using static functions (like your ByteArrayUtils) to create bytearray's used for communication, but it seems fine, even made tests using non static functions.
So, it looks like I have found the issue. Looks like it's the ByteArray that is doing it.
ByteArray.toString() is basically sometimes mangles your data meaning you can't really trust it.
http://www.actionscript.org/forums/showthread.php3?t=155067
If you read the comment by "Jim Freer" he mentions how strings sometimes do this.
My solution was to switch to using a JSON encoded string instead of ByteArray data in the message channel. The reason I was using bytearray data to begin with is because I wanted to preserve class definition information, which JSON doesn't do.

Writing a byte array to local disk fails in SL 4

I get a bytearray from the server which I want to write to my local disk. It's a spreadsheet and it's part of an export function.
This is what I do on the client:
Using oFileStream As New FileStream(path, FileMode.Create)
oFileStream.Write(excel, 0, excel.Length)
End Using
This is the error occuring on creating a new Filestream:
Btw: I know there are several threads about this issue, but none resolved my problem.
You can save the byte array on the server and provide a link to it on the client. That way, your client (SL) won't need to write anything.

What can be better way to send WBXML data to web server?

Please could you help me in sending a data from Mobile appication to Web Server in WBXML format ? I have got a bit to convert xml to wbxml but not getting how to send that to web server in efficient way ?
I'm not sure I fully understand your question but here goes...
You need to use a POST HTTP request, and write the WBXML data to the connection objects output stream. Here is a brief example, obviously you'll need more code for it to actually work:
byte[] wbxml = getMyWbxmlData();
HttpConnection conn = (HttpConnection)Connector.open("http://myserver.com/mywbxmlhandler");
conn.setRequestMethod(HttpConnection.POST);
OutputStream output = conn.openOutputStream();
output.write(wbxml);
InputStream input = conn.openInputStream(); // This will flush the outputstream
// Do response processing
That is all assuming your WBXML already includes the preamble, such as version number, public code page identifier etc.

Resources