Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

stevehicks

macrumors newbie
Original poster
Feb 28, 2010
2
0
Hi Guys

I'm writing a client that listens to messages that composed of ascii and binary strings. I want to use NSInputStream because I want to run the client on both Mac and GNUStep on Solaris. Here's a C struct that describes the first few fields of the messages :

Code:
    char messageType;
    char ProtoOrVer;
    uint16_t MsgLen;    
    uint32_t MsgSeqNum;
    uint64_t ClOrdID;
    char OnBehalfOfCompID[11];
    char Rule80A;
    char Account[12];
    char TechnicalOrdType;
    char ClearingFirm[8];
    char ClientID[8];
    char FreeText[18];
    char OpenClose;
    char ClearingHandlingType;
    char Filler1;
    uint16_t NoQuoteEntries;


I've looked at the NSInputStream reference but it only reads uint8_t at a time. I think I probably need to override read:maxLength: to do this...what do you think ?? If so, any tips ?? I've not been able to find an example of how to do it :(

Any pointerrs greatly appreciated !!!

thanks :)
 

chown33

Moderator
Staff member
Aug 9, 2009
10,750
8,422
A sea of green
Why do you think you need to subclass NSInputStream at all?

It seems to me your client code simply asks the NSInputStream to read bytes into a buffer of length sizoef(myHeader), where myHeader is the struct definition you posted. You then perform any endian conversions needed on the non-char struct members, and bam, there's your struct in the buffer.

I don't know what you mean by "it only reads uint8_t at a time". Do you understand Objective-C? Do you realize that read:maxLength: takes a first parameter that is pointer to uint8_t, and a second parameter representing the max number of bytes to put at said pointer? The count of actual bytes put into buffer is returned. This is essentially identical to every read() or fread() function ever created.
 

stevehicks

macrumors newbie
Original poster
Feb 28, 2010
2
0
I'm just starting out with C and Objective C actually and I clearly misunderstood. Thanks for enlightening me so succinctly.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,750
8,422
A sea of green
I'm just starting out with C and Objective C actually and I clearly misunderstood. Thanks for enlightening me so succinctly.

Glad to have helped.

However, if you're just starting out with both C and Objective-C, then a project of this apparent complexity may not be the best choice.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.