[1.7.x] Fixed #22426 -- Added support old-style d.c.messages format.

Forward ported code from 1.5 that adds backwards compatibility with legacy message length.
See commit 9e7183073f64e541587e8dcfd8bb3ddeb47f8162 for details.

Thanks to Ofir Ovadia for the initial patch.

Backport of f286721f7fdc2202f77a5f4d650d9d0779b86811 from master.