[zeromq-dev] Difficulty/Confusion in understanding ZMTP
Holger Joukl
Holger.Joukl at LBBW.de
Tue Nov 3 08:17:20 CET 2015
Hi,
not being an authority on the subject, but got curious...
> I'm trying to understand the ZMTP protocol, so I was going through
> the RFC for version 1.0 [0]. It states that:
> The following diagram shows the layout of a frame with a length of 1
> to 254 octets:
> +----------------+
> Octet 0 | Length |
> +----------------+
> Octet 1 | Flags |
> +----------------+- ... ---------------------+
> Octets 2+ | Body Length - 1 octets |
> +------------------ ... ---------------------+
> But, what I don't understand is that if the total length is that of
> 254 Octets, and the first and second octets are occupied by the Length
> and the Flags part of the message respectively, how can the Body be from
> Octet 2 to (Length - 1) ? Shouldn't it be (Length - 2) , since the
> first two octets are occupied already?
Note that length includes the flags field but not length-octet itself:
"Specification
A ZMTP message consists of 1 or more frames.
A ZMTP frame consists of a length, followed by a flags field and a frame
body of (length - 1) octets.
Note: the length includes the flags field, so an empty frame has a length
of 1.
[...]"
> The RFC also says that,
> For frames with a length of 1 to 254 octets, the length SHOULD BE
> encoded as a single octet.
>
> The length being 1 Octet itself, can store a max value of 255. So my
> question is, why is the max length of a frame, 254 and not 255 ?
Note that frames can have a length >=255:
"For frames with lengths of 255 and greater, the length SHALL BE encoded as
a single octet with the value 255,
followed by the length encoded as a 64-bit unsigned integer in network byte
order. For frames with lengths of
1 to 254 octets this encoding MAY be also used."
Can't comment on the reasoning above (maybe to keep "short frames" in an
overall length of
255 = length-field-octet (1) + flags-and-body (max. 254)?), but:
"Known Issues
[...]
The specification of the length field is surprising (and has confused even
experts reading the spec). It should not include the flag field, nor other
possible header fields. This would allow a zero-length body to be specified
with a length of zero.
[...]"
And indeed this has changed in ZMTP 2.0 (http://rfc.zeromq.org/spec:15) and
3.0 (http://rfc.zeromq.org/spec:23).
Best regards,
Holger
Landesbank Baden-Wuerttemberg
Anstalt des oeffentlichen Rechts
Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz
HRA 12704
Amtsgericht Stuttgart
More information about the zeromq-dev
mailing list