0

My requirement is to convert an NSData stream that is written in 2 formats: hex bytes and normal string data (not sure what is correct name for it but if you have a look you can know).

I am trying to find a way to fetch important stuff from it.

Here is a sample:

bbbbbb02bbbbbb
bbbbbb

From the above part, I can fetch 02 using approach shown here. (bbbbbb is simply a delimiter)

However I am not sure about the following part - and I don't know what should I do to convert it into something sensible. Best I know it is an ascii character bytes formatted as xml. (note bbbbbb delimiter at the end)

3c3f786d....long pattern of hex....bbbbbb

I have already gone through this but the utf-8-encoded nsdata to nsstring conversion seems to require entire nsdata while I have bytes due to fragments of data that I need.

Can anyone put a sensible and cumulative approach to convert the entire pattern into required format ie bbbbbb02bbbbbb into 02, 3c3f786d.... into ascii xml and so on?

Community
  • 1
  • 1
Nirav Bhatt
  • 6,940
  • 5
  • 45
  • 89
  • It's hard to comprehend exactly what you want, but it sounds like you need to parse your data into individual components and then recombine them in the desired fashion. No magic, just programming. – Hot Licks Jan 26 '13 at 19:47
  • Sorry, I only know how fetch unimportant stuff :) – occulus Jan 26 '13 at 20:37
  • @HotLicks - definitely it is parsing challenge. And I am not particularly good at parsing bytes, chars, data and pointers. When I parse the whole data using initWithData:data encoding:NSUTF8StringEncoding, I get junk in place of bbbbbb, which are delim bytes. I can grab them using [NSMutableData appendWithFormat:@"%02x",dataBuffer[index]], where dataBuffer = [data bytes]; If you could point me to an existing code source which is similar to this, will be highly thankful. – Nirav Bhatt Jan 27 '13 at 06:48
  • By "parse" I mean write code that looks at the data, decides what the next sequence of bytes is, and substrings the data accordingly. There will be no "magic" formula or API to do this since (presumably) your incoming format is somewhat "ad hoc" and does not conform to any common format. – Hot Licks Jan 27 '13 at 23:38
  • OK, finally it got simplified till the point where I get string like 3c3f 786d6c20 76657273. I know this is hex representation of ascii xml. I get this data into one of my nsmutablestring. How do I convert it into ascii xml? – Nirav Bhatt Jan 29 '13 at 05:17

0 Answers0