It sounds like an X12-style EDI format. They'll frequently have fields (or parts of fields) that can enable alternative blocks that may be of a different size. I had to write and maintain EDI interfaces for four years at a major retailer: there's a good business in transforming those documents.
It's not as weird as it sounds, you're parsing a text stream, not that much different in principle than parsing HTTP headers or network packets byte by byte.
Care to post a mini-example with fake data so we can better understand what you are describing?