Load string from Delphi stream in Oxygene -
I am new to oxygen and I want to read the strings from a stream which was produced by Delphi. I get this stream through TCP Here's how I save strings on the client side:
As you can see, I first add the size of the string of the stream and then the content. My current method of loading a wire from a stream on the server side (oxygen) looks like this:
"LoadStringFromStream" (const aStream: NSInputStream): String; Start Var Bluff: array of [1024] uint8_t; Var len: integer: = 0; Lane: aStream. Read more (buff) Maximax (1024); If LAN & gt; 0 Then start the len.stringValue; Var data: NSMutableData: = NSMutableData.alloc (). InitWithLength (0); Data.appendBytes (@buf) Length (Buff [0]); Exit NSString.alloc () InitWithData (Data Encoding) (NSStringEncoding.NSASCIIStringEncoding); End; End;But this hole gives content and not the current part.
EDIT: Oh, I had a mistake in the server application ... Now I am able to read the wire, but not to read the integer values (up to 256 bit only) for the purpose-C I found this code
- (int32_t) readInt32 {int32_t value = 0; If ([Self reading: (uint8_t *) and value maximum length: 4]! = 4) {NSlog ("***** int32 could not be read"); } return value; }
Oxygen Code that:
function readInt32 (const aStream: NSInputStream): integer; Start Val Value: int32_t: = 0; Var tmp: = uint8_t (@value); If the Esteem Read more (@TMP) MaxLentham (4) & lt; & Gt; 4 Then NSLog ('*****' can not read 'int32); Exhaust Price; End;
But something went wrong, I did not get any value. Do you guys know what I have to do?
I think you changed the objective-C code (slightly, but quite a lot) wrongly From:
function readInt32 (const aStream: NSInputStream): integer; Start Val Value: int32_t: = 0; Var tmp: = uint8_t (@value); If the Esteem Read more (@TMP) MaxLentham (4) & lt; & Gt; 4 Then NSLog ('*****' can not read 'int32); Exhaust Price; End;
The TMP in the above code is declared as a single byte and addresses < / Em> value variable
If the value variable is being stored at the memory address $ 12345678 (stupid example is kept for 32-bit summarized) then < TMP will be started with the value of $ strong> $ 78 then you pass the address of aStream.read () to the tmp variable Which attempts to read <4> bytes in the location of the tmp variable. But TMP is only 1 byte value !
I think you need to change the announcement of TMP to make it Indicator to unit8_t and then Pass it directly on aStream.read () :
var value: Int32_t: = 0; Var tmp: = ^ uint8_t (@value); If the Esteem Read more (TMP) Max Lentham (4) & lt; & Gt; 4 Then NSLog ('*****' can not read 'int32); End the
or TMP variable and pass value address to an appropriate artist:
var value: int32_t: = 0; If aStream & Amp; Read (^ uint8_t (@value)) maxLength (4) & lt; & Gt; 4 Then NSLog ('*****' can not read 'int32);
This latter approach is directly comparable with the objective-origin.
Comments
Post a Comment