Fwd: Quick way to convert hex string represented in ASCII to binary?
Fwd: Quick way to convert hex string represented in ASCII to binary?
- Subject: Fwd: Quick way to convert hex string represented in ASCII to binary?
- From: Ken Tozier <email@hidden>
- Date: Sat, 29 Jul 2006 05:07:12 -0400
Begin forwarded message:
From: Ken Tozier <email@hidden>
Date: July 29, 2006 5:05:22 AM EDT
To: Andreas Mayer <email@hidden>
Subject: Re: Quick way to convert hex string represented in ASCII
to binary?
On Jul 29, 2006, at 4:03 AM, Andreas Mayer wrote:
NSData *xmlData = [NSPropertyListSerialization
dataFromPropertyList:inputData format:NSPropertyListXMLFormat_v1_0
errorDescription:NULL];
To get the data back:
NSData *outputData = [NSPropertyListSerialization
propertyListFromData:xmlData
mutabilityOption:NSPropertyListImmutable
format:NSPropertyListXMLFormat_v1_0 errorDescription:NULL];
Thanks Andreas,
I was just checking NSPropertyListSerialization out but I'm not
sure it will work in my situation. Would the XML data be surrounded
by start and end tags? If so, it won't work for me. In a nutshell,
here's what I'm trying to do:
Given an AliasHandle, i need to pack it into PHP serialization
format. I know how to do that for all data types except binary
data. For example, here are a few categories that show what I have
to do
// For NSStrings
- (NSString *) serializeAsPHP
{
return [NSString stringWithFormat: @"s:%i:\"%@\";", [self length],
self];
}
// For NSNumbers
- (NSString *) serializeAsPHP
{
return ([self intValue] == [self floatValue]) ? [NSString
stringWithFormat: @"i:%i;", [self intValue]] : NSString
stringWithFormat: @"i:%f;", [self floatValue]];
}
// For NSCalendarDates
- (NSString *) serializeAsPHP
{
NSString *temp = [self descriptionWithCalendarFormat: @"%Y-%m-%
d %H:%M:%S"];
return [NSString stringWithFormat: @"s:%i:\"%@\";", [temp length],
temp];
}
// and here's what I was doing for NSData
- (NSString *) serializeAsPHP
{
NSString *temp = [self description];
return [NSString stringWithFormat: @"s:%i:\"%@\";", [temp length],
temp];
}
Output from the above would look like this
"Hello World" -> s:11:"Hello World";
3.1415926535 -> f:3.1415926535;
2006-07-29 12:00:00 -> s:19:"2006-07-29 12:00:00";
And I need to do the same thing with NSData objects, ie pack it
into a string. Would some sort of NSCoder be able to do this? I've
never used coders and looking at the documentation here: http://
developer.apple.com/documentation/Cocoa/Reference/Foundation/
Classes/NSCoder_Class/Reference/Reference.html#//apple_ref/occ/
instm/NSCoder/encodeDataObject:
I'm not entirely clear on how to use that. The little "-" indicates
that it's an instance method but an instance of what? NSCoder?
If you (or anyone else) can think of a way to pack an NSData in a
better way that above, I'd actually prefer it to having to decode
hex by hand
Thanks
Ken
(Code untested; written in Mail)
Andreas
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40comcast.net
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden