Skip to main content

frame

Function frame 

Source
pub fn frame(opcode: Opcode, payload: &[u8]) -> Vec<u8> ⓘ
Expand description

One unfragmented frame, from the server, unmasked as RFC 6455 requires of a server.

use majordomus_cli::http::ws::{frame, Opcode};
assert_eq!(frame(Opcode::Text, b"hi"), vec![0x81, 0x02, b'h', b'i']);
assert_eq!(&frame(Opcode::Ping, b"")[..2], &[0x89, 0x00]);
// a payload of 126 bytes or more carries an extended length
assert_eq!(&frame(Opcode::Text, &[b'x'; 200])[..4], &[0x81, 126, 0, 200]);