# binpac: variable length

**URL:** <https://community.zeek.org/t/binpac-variable-length/1659>\
**Category:** Zeek\
**Created:** [September 9, 2010, 8:41pm UTC](https://community.zeek.org/t/binpac-variable-length/1659 "2010-09-09T20:41:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![da5id\_psp](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@da5id\_psp](https://community.zeek.org/u/da5id_psp)\
**Post date:** [September 9, 2010, 8:41pm UTC](https://community.zeek.org/t/binpac-variable-length/1659/1 "2010-09-09T20:41:28Z")

</div>

Hi, I’m using binpac as a standalone parser for RTMP ([http://www.adobe.com/devnet/rtmp/](http://www.adobe.com/devnet/rtmp/))

RTMP is a binary protocol that does not delimit frames/chunks like other fixed frame protocols. eg. An RTMP chunk can be of type 0-3, the only way to find the length is to first read the whole packet and then derive the length depending on the chunk type.

My question is how can I do this in binpac since the enclosing record expects a length but it can only be provided after parsing the child records, eg.

type Chunk0 = record {  
msgLen:uint32;  
};

type Chunk0 = record {  
chunkId:uint32;  
} &let {  
msgLen = # calculated from chunkId  
};

type Chunk = record {  
basicHeader:uint8;  
chunk: case basicHeader of {  
0 → chunk0:Chunk0;  
1 → chunk0:Chunk1;  
2 → chunk0:Chunk2;  
3 → chunk0:Chunk3;  
}  
data: bytestring &restofdata;  
} &length = ???;

Any help will be appreciated. Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/zeek/original/1X/f09d732bc2cc7c7cc7e35db67cf4e1d5233ce7a7.png) [@system](https://community.zeek.org/u/system)\
**Post date:** [May 6, 2022, 3:39pm UTC](https://community.zeek.org/t/binpac-variable-length/1659/2 "2022-05-06T15:39:10Z")

</div>


