[Y-devel] Proposal for a minor change in the Y-protocol

Andreas Karafyllis ankar at homodigitalis.net
Sun Apr 11 13:51:30 BST 2004


Hi everybody,

If am currently implementing Eiffel-bindings for Y and I noticed thet the way 
string are serialized as message-members can be improved.

Currently (I am talking about the latest version after patch 33), a string is 
serialized as following:
00 - 03: Member length without this field
04 - 07: Type information (0 for strings)
08 - XX: The string including the 0 character.

XX is the value of "Member length" + 3
Example: The string "Hello" will be serialized as following:

00 - 03: 10
00 - 07: 0
08 - 12: 'H', 'e', 'l', 'l'
13 - 14: 'o', '\0'

In the comments in the libYc is written thet the '\0' may be not used in the 
future. I go for it. The '\0' is not needed. You should depend to "member 
length" field find how big the string is. And null terminated strings are a 
bad idea anyway. A very nice article about this topic is the following:
https://www.joelonsoftware.com/articles/fog0000000319.html

With or without the null character there is still a small problem. The next 
field could start in an address which is not 4-byte aligned. If the next 
member is for example an integer, all its field wills be stored in no 4-bytes 
aligend addresses. There are to reason I do not like it:
1) It is ugly :-)
2) Most modern  RISC processors do not work very happily with not-aligned 
values. We should try to make serialization - deserialization as fast as 
possible

Therefore, I suggest the following format:
00 - 03: Member length without this field
04 - 07: Type information (0 for strings)
08 - 12: String length
08 - XX: The string padded with zeros in case string_length modulo 4 not equal 
to zero

XX in like before "Member length" + 3
Using this format the above example will be serialized like this:
00 - 03: 16
00 - 07: 0
08 - 12: 5
12 - 15: 'H', 'e', 'l', 'l'
16 - 19: 'o', '\0', \0','\0'

I suggest that a similar approach is followed in the future for all fields 
that have a variable size

Bye

Andreas




More information about the Y-devel mailing list









2026 © www.Y-Windows.Org - All Rights Reserved