Enforce String Lengths when writing


Since we've adopted a principle of surfacing data during writing loss as exceptions (encoding, etc.), we should enforce defined string lengths. Since the v4 spec defines only fixed-length strings of length 1, we could do this strongly by making those fields chars, or by enforcing the length at write time.

I originally didn't use chars because you'd then have 3 kinds of strings: self-length, fixed > 1, and fixed == 1. I was trying to express the full possibilities of the spec, so I wanted to limit the special cases as much as possible.

Now the right choice is not as clear to me.


Selzhanik wrote Apr 11, 2012 at 5:18 PM

I've added reader and writer methods for single characters, and arrays of single characters, because I think we're going to end up going that direction. The spec only defines Cn (string) and C1 (char). There is no C6, or any other number. It does have kxCn's (arrays of variable length strings) which are now supported as arrays of strings. I think if we ever did find a need to support a "C6", we could do so as a "6xC1" -- a fixed-length array of characters, as opposed to a fixed-length string.