|
|
Log in / Subscribe / Register

A new API for mounting filesystems

A new API for mounting filesystems

Posted Apr 3, 2017 17:00 UTC (Mon) by Cyberax (✭ supporter ✭, #52523)
In reply to: A new API for mounting filesystems by sorokin
Parent article: A new API for mounting filesystems

XML is way too complex (namespaces, entities, ...) but JSON (or one of its binary counterparts like BSON) would indeed be a welcome addition.

> You mentioned that having '\0' have some downsides, but you did not specify which ones exactly.
Several languages make it difficult to work with \0-containing strings, like good old bash or C.

> On the other hand I see a (in my optinion) significant downside of your encoding. With known lengths of the values it is very easy to calculate the required buffer size with zero terminated strings. In your case calculating the buffer size in advance is complicated.
I don't follow. In a case of \0-terminated array of dynamically-sized strings calculating the total length would require traversal of the whole array with parsing along the way.


to post comments

A new API for mounting filesystems

Posted Apr 3, 2017 17:33 UTC (Mon) by Homer512 (subscriber, #85295) [Link] (3 responses)

>> On the other hand I see a (in my optinion) significant downside of your encoding. With known lengths of the values it is very easy to calculate the required buffer size with zero terminated strings. In your case calculating the buffer size in advance is complicated.
> I don't follow. In a case of \0-terminated array of dynamically-sized strings calculating the total length would require traversal of the whole array with parsing along the way.

I think the point is that with \0-terminated strings, you can precalculate the buffer size by summing strlen() of the parts. With a prefixed string, you have to add ceil(log10(strlen())) + 1 or something like that to account for the length.
The simplest workaround in plain old C is to use snprintf(NULL, 0, format, …) and use the return value to allocate the actual buffer.

A new API for mounting filesystems

Posted Apr 3, 2017 17:34 UTC (Mon) by Cyberax (✭ supporter ✭, #52523) [Link] (2 responses)

With my scheme there are no \0 symbols in the mix. So just get strlen() of the whole thing.

A new API for mounting filesystems

Posted Apr 3, 2017 20:58 UTC (Mon) by khim (subscriber, #9252) [Link] (1 responses)

It's impossible to call strlen till you allocate butter and put all the data into it. And calculating size of buffer is not trivial

A new API for mounting filesystems

Posted Apr 3, 2017 21:02 UTC (Mon) by Cyberax (✭ supporter ✭, #52523) [Link]

And how is that different from a bag of \0-terminated key-value pairs?

A new API for mounting filesystems

Posted Apr 4, 2017 5:01 UTC (Tue) by jhoblitt (subscriber, #77733) [Link]

msgpack is probably the most consistent and performant binary encoded equivalent of JSON. It would certainly be a great thing to start using a standardized data interchange format rather that using a hand rolled format for anything that isn't performance critical (i.e., called 1000+ per second). However, I wouldn't hold my breath, the kernel community is still holding on to C90.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds