How to retrieve sequence<float> in ObjC?

oxrideroxrider Member Tengyu LiuOrganization: UIUCProject: Cockpit for fund
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

  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    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]];
    }
    
  • oxrideroxrider Member Tengyu LiuOrganization: UIUCProject: Cockpit for fund
    Thank you so much!
Sign In or Register to comment.