evanw / kiwi

A schema-based binary format for efficiently encoding trees of data

Home Page:http://evanw.github.io/kiwi/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A description of a format

photopea opened this issue · comments

Is there any description of a format? I was able to understand almost everything from your demo at http://evanw.github.io/kiwi/, but I am still confused by floats.

How is "7e cc cb cb" converted to 0.8980392217636108 ?

I guess it is not IEEE 754, or is it?

Ok, I found it in your code: bits = (bits << 23) | (bits >>> 9);

But I still think you should make a public description. Eg. I need a kiwi decoder in under 3 kB of Javascript, but your kiwi.js is 70 kB, so I need to implement it myself. But the format is not described anywhere :/

Yeah you're right, I should definitely write up a more detailed description. However I did a quick experiment and I think I can generate a 3kb js library pretty easily from the current source code. Can you say a bit more about what you'd want specifically? I'm assuming parsing a binary version of the schema into JavaScript code that decodes and encodes messages is what you're looking for if you're optimizing for compactness. Is that right?

Edit: One more question: are you trying to parse the Figma file format? Or are you using this for your own purposes?

I already finished my parser and it is under 3kb :) I made a parser for Protocol Buffers a week ago, which is also quite small.

Yes, I would like to parse Figma format. Are you (as the author of Figma) ok with it?

I can already parse a document tree, so now, I just need to turn it into a PSD somehow.

Yeah I’m fine with it. You are of course free to do whatever you like with this library :)

I just asked because if you are parsing raw Figma files, you should know that this is our internal format which is not intended to be stable. Our HTTP API and our plugin API are the things we intend to be stable. For example, an alternative approach could be to create a Figma plugin to export to PSD. The plugin API is our intended way of consuming Figma files and is something we work very hard to keep stable.

There are a lot of things about our internal file format that we are planning to change. For example, we are about to overhaul how shared components are represented. We also plan to completely change the format at some point to improve loading performance. So building something on our internal format is likely to break many times in the future.

That is exactly what Adobe told me when I decided to implement Adobe XD :D

By the way, did you do any experiments about the file size? Is Kiwi really smaller than Protocol Buffers or ZIPped JSON (Sketch, XD)?

Certain things are slightly smaller. For example, the fields of a struct type are stored consecutively without any field labels. It's basically the same as protocol buffers though. The important difference is the optional fields feature, which Figma uses to send partial messages.

Related to the structure of Figma files: There are INSTANCEs of symbols. A referred symbol has e.g. 3 direct children, however, an instance has 5 elements in "symbolOverrides".

How does Figma determine, which override belongs to which sub-child of a Symbol? You can reply to support@photopea.com :)

Sorry, we don’t offer support for Figma’s file format. The file format is deliberately internal and undocumented.

I will close this issue now. I understand, that Kiwi was probably created for Figma, but it would be nice to document it, so that others can use it easily.

@evanw BTW. I added the .FIG support to Photopea yesterday: https://blog.photopea.com/photopea-4-6-open-figma-files.html

It would be nice, if you mention Photopea in your article: https://help.figma.com/hc/en-us/articles/360040030374 :)

@photopea any plans of publishing that reader library?
Was thinking of using it as a replacement for pb/thrift, but the decoding library would be the largest dependency in our project

@evanw Hi Evan, is there any chance to discuss something with you? I am the founder of Photopea.com , you can send me a message at https://twitter.com/photopeacom (there is no message button at your Twitter account).