Simon Kornblith
unread,Dec 16, 2012, 12:28:02 PM12/16/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to juli...@googlegroups.com
Looking at Patrick's StrPack.jl module, I noticed that he has pulled the s_str macro that's in the version of strpack.jl in extras. I can't say I really miss it, but for a project I'm working on I need to be able to specify structs containing arrays of fixed lengths, and I didn't see an obvious way in the new StrPack module. I ended up writing a short macro that takes code like:
@struct PL_EventHeader begin
Name::ASCIIString(32)
Channel::Int32
Comment::ASCIIString(128)
Padding::Int32(33)
end
and creates a type that looks like:
type PL_EventHeader
begin
Name::ASCIIString
Channel::Int32
Comment::ASCIIString
Padding::Array{Int32, 1}
end
end
and a corresponding function read(ios::IOStream, ::Type{PL_EventHeader}) to read the struct out of a file as a PL_EventHeader.
For my use case, I didn't have to deal with alignment or serializing structs to bytes, so the macro is quite simple, but I wonder whether it's worth trying to integrate something similar into strpack. Or maybe someone has a better idea that doesn't abuse the AST.
Simon