Re: encoding over DO
- From: "Wizumwalt@xxxxxxxxx" <Wizumwalt@xxxxxxxxx>
- Date: 28 Apr 2007 12:04:23 -0700
"bycopy makes so much sense for certain classes-classes that are
intended to contain a collection of other objects, for instance-that
often these classes are written so that a copy is sent to a remote
receiver, instead of the usual reference. You can override this behavior
with byref, however, thereby specifying that objects passed to a method
or objects returned from a method should be passed or returned by
reference."
Therefore, your NSMutableArray, in all likelyhood, would be passed
bycopy and in that process have its encodeWithCoder: method messaged.
Did you specify byref in your DO protocol instead?
No-where's do I specify byref in my DO protocol.
I do query the object I pull off my NSMutableArray on the receiving
end for it's class and I get "class <NSDistantObject: 0xa2bdca18>".
I'm actually a bit confused on how it's sort of working because if my
encoder methods are not being called, how is the data on the receiving
end being received (it seems to know the correct size of the array,
but the objects in it aren't correct)?
I stuff 250 objects into an NSMutableArray on the sending side (that
would be the allPatterns instance below). Then I pass that array to
the receiver through DO with a line like [server setPatterns:patterns]
and on the receiving side where the pointer to this array just get's
stored.
Then the sending side sends a command over DO to operate on the array
on the receiving end. I can see that my NSMutableArray has the correct
size, but I'm pretty sure the data within it isn't correct.
And I do send other objects over DO and those classes do come through
fine w/ their correct data, but only because I think they are obj-c
objects all the way through. One thing about this array that I'm
populating before sending is that my objects are c++ classes and I'm
stuffing them in an obj-c wrapper class and trying to serialize them.
// Stuff c++ pattern objects into NSMutableArray
PatternWrapper *wrapper =
[[PatternWrapper alloc] initWithPattern:pattern];
[allPatterns addObject:wrapper];
// ---------
@interface PatternWrapper : NSObject {
AB::Pattern *pattern;
}
- (id)initWithPattern:(AB::Pattern *)nativePattern;
- (void)encodeWithCoder:(NSCoder *)encoder;
- (id)initWithCoder:(NSCoder *)decoder;
@implementation PatternWrapper
- (id)initWithPattern:(AB::Pattern *)nativePattern
{
if (self) {
pattern = new AB::Pattern(nativePattern);
}
return self;
}
// This method never get's called.
- (void)encodeWithCoder:(NSCoder *)encoder
{
NSLog(@"encodeWithCoder:");
NSLog(@"encoder isBycopy:%d", [encoder isBycopy]);
[super encodeWithCoder:encoder];
// this line calls the c++ class where I'm trying
// to natively serialize the object (for performance).
std::string pat = AB::pattern->str_pattern();
NSLog(@"pat:id = %@", pat);
NSLog(@"pat:id = %@", pat.c_str());
[encoder encodeBytes:pat.c_str() length:pat.size() + 1];
/*int serial = pattern.serial();
[coder encodeValueOfObjCType:@encode(int) at:&serial];
*/
}
Any help much appreciated.
.
- Follow-Ups:
- Re: encoding over DO
- From: Patrick Machielse
- Re: encoding over DO
- References:
- encoding over DO
- From: Wizumwalt@xxxxxxxxx
- Re: encoding over DO
- From: Patrick Machielse
- encoding over DO
- Prev by Date: Re: PowerPC assembly question
- Next by Date: Convert NSDictionary to NSData
- Previous by thread: Re: encoding over DO
- Next by thread: Re: encoding over DO
- Index(es):
Relevant Pages
|