开发者

What kind of data does apple use on GLPaint example?

Few months ago i made an app based on apple GLPaint. It works great.

I have recorded sets of points that draw simple drawings on the screen. and saved them as array of points (converted to NSValue).

i am trying to improve my app now and i looked again at apple example. the data in their data file looks like that (i have changed it a little bit):

<data>
AAC8QgAAsEMAAMJCAICoQwAAwkIBBAKRDAADCQgCAnUMAAMJCAACYQwAAwEIAgJRDAADA
QgCAkkMAAMBCAACRQwAAwEIAgJBDAADAQgCAkEM=
</data>
<data>
AACoQgAAnEMAALpCAACdQwAAxEIAAJ1DAAGGGgAAnUMAANpCAICdQwAA4kIAgJ5DAADs
QgCAn0MAAOxCAICfQw==
</data>

So every group is one drawing and This is way compact then my plists of CGPoints.

I have succeeded to convert the array of CGPoints to data and read the file back.

BUT When i try to open each shape data file i get this (on textMate, textEdit, xCode...):

What kind of data does apple use on GLPaint example?

I wish to understand:

  1. What does apple use to get this compressed format of the CGPoints list?
  2. 开发者_如何转开发
  3. how can i open my data file in more readable way?


The data in Apple's Recording.data file in that sample application is the XML Plist representation of an NSArray containing a bunch of NSData objects, each of which contains the bytes representing an array of CGPoint structs. Do note that this depends on the binary representation of a CGFloat and the specific layout of the CGPoint struct, which could differ between compilers or versions of the same compiler.

Your screenshot appears to be the output of NSKeyedArchiver, which is safer but has much more overhead.

If you wanted a compact but still portable representation, you could manually serialize the individual CGFloats into a byte array in a portable format (this previous question may help you there) and then wrap the byte arrays in NSData, put the NSDatas into an NSArray, and use writeToFile:atomically: to output the mess to a plist like Apple does.


This appears to be Base64. This page mentions it:

Note that data bytes are base-64 encoded between the <data> and </data> tags.

<data> is for NSData, which you can get from an array by using +[NSKeyedArchiver archivedDataWithRootObject:].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜