data encoding/decoding on the server looks weird
Closed this issue · 2 comments
I can see that both publishString
and publishData
publish NSData
to the MQTT server. I have a small issue, I'm not sure if it is related to this lib though.
I'm using mosquitto in ruby, but when I subscribe and read the message it looks very funny, I almost cannot identify anything from what I actually publish:
bplist00RST$topX$objectsX$versionY$archiver�Troot��
!"#$%&'/;<=>JKLMU$null�
V$classZNS.objects����
��
WNS.keys��� �
�
�����UmajorUminor]proximityUUIDYtimestamp_$B9407F30-F5F8-466E-AFF9-25556B57FE6D_1400338443.678084�()*.X$classesZ$classname�+,-_NSMutableDictionary\NSDictionaryXNSObject_NSMutableDictionary�
��� 06�234��
�����_$B9407F30-F5F8-466E-AFF9-25556B57FE6D_1400338443.678005�
?E�ABC�����
�����_$B9407F30-F5F8-466E-AFF9-25556B57FE6D_1400338443.678049�()NQ�OP-\NSMutableSetUNSSet\NSMutableSet��_NSKeyedArchive(25:<TZ_fqswy{}��������������������
$(>KTjqvxz|~����������������������*/3@FSXTj
Is there anything I can do on the iOS end? Or is it on the other end where I read the data?
What are you publishing?
It looks like you are sending directly the bytes from a NSDictionary
object. The ruby client will not be able to decode that.
You could instead send a JSON object that can then be parsed on the ruby receiving side. Something like:
NSDictionary *dict = ...
NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:0 error:nil];
[self.client publishData:data
toTopic:topic
withQos:AtMostOnce
retain:YES
completionHandler:nil];
It's a [NSKeyedArchiver archivedDataWithRootObject:data];
data object, and the data
is a NSSet
. Should I convert that set to what you suggest instead of using the NSKeyedArchiver
?
EDIT: I am doing the following now:
NSSet *set = [self filter:[NSSet setWithArray:beacons]];
NSSet *data = [self project:set];
NSError *jsonSerializationError = nil;
@try
{
self.data = [NSJSONSerialization dataWithJSONObject:[data allObjects] options:(NSJSONWritingOptions) kNilOptions error:&jsonSerializationError];
}
@catch (NSException * __unused exception)
{
self.data = [[NSData alloc] init];
}
I'll try it out and let you know if it works out.
Confirmation: It was what you have suggested, I have converted the set to the proper object and created the data, now I can see the result I expected.