JuliaLang/julia — pull request #694 by pao (2012-04-10 03:23:38+00:00)
Title: RFC: Binary strings/streams<->composite types (aka struct.jl)

Bringing this here for some more thought/review. Arrays are kind of weak; I don't have a good idea how to support them from existing types. I hack my way around it in the generated struct types; do we need to introduce fixed-size arrays (#593)? Or is there another solution that isn't horrible?

Strings are a very weak spot. Why is `read(in, Char)` different from `read(in, Char, 1)`?

```Julia
julia> tmp = memio(); write(tmp, "abcdefghijklmnopqrstuvwxyz")
julia> seek(tmp, 0); read(tmp, Char)
'a'

julia> seek(tmp, 0); read(tmp, Char, 2)
['', '']
```

The current struct string syntax:

```
struct_string := endianness? element_specifier*
endianness := "<" | ">" | "!" | "=" | "@"
element_specifier := name? size? type
name := "[" identifier "]"
size := unsigned_integer | "(" unsigned_integer ("," unsigned_integer)* ")"
type := predefined_type | "{" identifier "}"
predefined_type := "x" | "c" | "b" | "B" | "?" | "h" | "i" | "I" | "l" | "L" | "q" | "Q" | "f" | "d"
```
String examples: `s"3bxd"`, `s">[name]($rows, $cols){Complex128}"`

Usage example:
https://gist.github.com/2333148