Re: stream io & ObjC
Re: stream io & ObjC
- Subject: Re: stream io & ObjC
- From: Peter Ammon <email@hidden>
- Date: Fri, 29 Jun 2001 16:48:44 -0700
on 6/29/01 11:56 AM, Candide Kemmler at email@hidden wrote:
>
Hi !
>
>
Sorry for asking, but I'm a beginner with any language that's not Java
>
(means I don't even know C!).
>
>
I've turned to ObjC for my current project because I felt that using
>
Java would hamper performance, and I also got strange errors related to
>
the java bridge that didn't make me feel comfortable with the java-cocoa
>
option.
>
>
So now, I'm left with having to learn not only cocoa, but Objective-C
>
also. I fear that I might have to learn a bit of C too now.
Yes, that's probably inevitable. But you'll be better for it. ;)
>
>
Indeed, I searched for an equivalent to java's java.io package that
>
allows to parse a stream and read its content according to the type of
>
data you expect. For example, if you expect to receive a polygon, you
>
could first read the number of coordinates with readInt (), and then
>
-let ncoords be the number of coordinates in the polygon, iterate
>
ncoords times to read the x and y coordinates of every vertex of the
>
polygon using readFloat ().
>
>
I didn't find such functionality in the Foundation classes. I downloaded
>
2 libraries (frameworks) from the Omni Group (namely OWF and
>
OmniNetworking), but they seem to provide only very basic capabilities
>
(such as reading lines of text, or an entire array of bytes at once).
Cocoa gives you that functionality in the NSCoder class and associated
NSCoding protocol. The rough analog of "stream" is "NSCoder". Once you've
got your coder, decoding into primitives is as simple as
[coder decodeValueOfObjCType:@encode(int) at:&myInt];
and objects are even simpler:
myObject = [coder decodeObject];
>
>
I'd really appreciate some information or pointers about using an array
>
of bytes for such things like making an int out of 4 bytes, or a
>
float,... as a possible alternative. I'll have to use C for that, won't
>
I ?
You can do that stuff in straight C, but the NSCoder class is much easier.
-Peter