It's not a matter of making it longer. Per the RFC 6455:
- If the length is 0-125, that is the payload length.
- If 126, the following 2 bytes interpreted as a 16-bit unsigned integer are the payload length.
- If 127, the following 8 bytes interpreted as a 64-bit unsigned integer (the most significant bit MUST be 0) are the payload length.
The length has to be sliced into separate bytes, which means you'll need to bit-shift to the right (with an amount of eight bits), and then only retain the last eight bits by doing and 1111 1111
(which is 255
).
This answer goes over this principal in great detail.