Archived

This forum has been archived. Please start a new discussion on GitHub.

How to retrieve sequence<float> in ObjC?

Sorry for spamming the forum, I'm really new to this and need heavy help...

So I'm trying to return a sequence<float> from server (cpp) to client (objc), and I'm stuck in how to decode the returned NSData. What I'm trying to do is:
    NSMutableArray someArray...   //Initialize someArray
    for (int i = 0; i < seq.length; i+=(int)sizeof(float)) {
        float f;
        NSString * s = [NSString stringWithFormat: @"{%d, %d}", i, i+(int)sizeof(float)-1];
        [seq getBytes:&f range:NSRangeFromString(s)];
        NSNumber * num = [NSNumber numberWithFloat:f];
        [someArray addObject:num];
    }

but the returned message is not what I am expecting. Can anyone help me look at it? Thanks a lot!

Comments

  • benoit
    benoit Rennes, France
    Hi,

    See the examples from the Ice manual here. For floats, it's the same thing as for ints:
    NSMutableArray someArray = [NSMutableArray array];
    const ICEFloat *p = (const ICEFloat *)[seq bytes];
    int limit = [is length] / sizeof(ICEFloat);
    int i;
    for(i = 0; i < limit; ++i) {
        [someArray addObject:[NSNumber numberWithFloat:p[i]];
    }
    
  • Thank you so much!