[1.5.x] Added compatibility with legacy message length

Added compatibility code to not break when decoding messages
encoded on pre-1.5 versions.
Refs #19387. Thanks Florian Apolloner for noticing the issue.