I have a protocol whose on-the-wire format is already defined and I'd like to use ASN.1 to encode/decode it, but it seems to break the defined BER/DER/PER options. For whatever reason, the protocol developers did not put payload sizes/lengths immediately before the payload itself - so I can't use the automatic BER/DER. But since the payload can be variable length, I can't use PER either. Here's an example:
12'b 12'b 4'b 4'b
|------------|--------------|-------|------|
| some stuff | payload size | blah2 | blah | Header
|------------------------------------------|
| payload word 1 |
|------------------------------------------|
| ... | Payload
|------------------------------------------|
| payload word N |
|------------------------------------------|
| much stuff | many bits | such doge | wow | Trailer
|------------------------------------------|
So maybe two questions here:
- Is there a way using one of the ASN.1 encodings to specify certain fields as the length for a later field - so you could say something like bits 9-20 contain the length for bits 33-N*32, but you're skipping bits 21-32 which can have other unrelated junk in them?
- I can see how an algorithm / rule could be written to support the above, so if there isn't a way to currently do this with ASN.1, is there a way (and documentation) on how to write a new rule or extension of some kind to the existing encodings?
EDIT
To clarify why I'm bringing up ASN.1, without repeating a previous question, is because it's almost exactly what I'm looking for - just apparently without a way to handle the particular use case I'm asking about here. I need to deserialize existing binary protocols and I'd rather not write my own since there are already many tools claiming they can do some form of this. If someone has another suggestion I'd gladly try it.