async function readFrame(buf) {
  let b = await buf.readByte();
  assert(b !== null);
  let isLastFrame = false;
  switch (b >>> 4) {
    case 8:
      isLastFrame = true;
      break;
    case 0:
      isLastFrame = false;
      break;
    default:
      throw new Error("invalid signature");
  }
  const opcode = b & 15;
  // has_mask & payload
  b = await buf.readByte();
  assert(b !== null);
  const hasMask = b >>> 7;
  let payloadLength = b & 127;
  if (payloadLength === 126) {
    const l = await readShort(buf);
    assert(l !== null);
    payloadLength = l;
  } else if (payloadLength === 127) {
    const l = await readLong(buf);
    assert(l !== null);
    payloadLength = Number(l);
  }
  // mask
  let mask;
  if (hasMask) {
    mask = new Uint8Array(4);
    assert(await buf.readFull(mask) !== null);
  }
  // payload
  const payload = new Uint8Array(payloadLength);
  assert(await buf.readFull(payload) !== null);
  return {
    isLastFrame,
    opcode,
    mask,
    payload,
  };
}
/** Read websocket frame from given BufReader
 * @throws `Deno.errors.UnexpectedEof` When peer closed connection without close frame
 * @throws `Error` Frame is invalid
 */
Read websocket frame from given BufReader
@throws `Deno.errors.UnexpectedEof` When peer closed connection without close frame
@throws `Error` Frame is invalid
Read websocket frame from given BufReader @throws ` Deno . errors . UnexpectedEof ` When peer closed connection without close frame @throws ` Error ` Frame is invalid
async function readFrame(buf) {
  let b = await buf.readByte();
  assert(b !== null);
  let isLastFrame = false;
  switch (b >>> 4) {
    case 8:
      isLastFrame = true;
      break;
    case 0:
      isLastFrame = false;
      break;
    default:
      throw new Error("invalid signature");
  }
  const opcode = b & 15;
  b = await buf.readByte();
  assert(b !== null);
  const hasMask = b >>> 7;
  let payloadLength = b & 127;
  if (payloadLength === 126) {
    const l = await readShort(buf);
    assert(l !== null);
    payloadLength = l;
  } else if (payloadLength === 127) {
    const l = await readLong(buf);
    assert(l !== null);
    payloadLength = Number(l);
  }
  let mask;
  if (hasMask) {
    mask = new Uint8Array(4);
    assert(await buf.readFull(mask) !== null);
  }
  const payload = new Uint8Array(payloadLength);
  assert(await buf.readFull(payload) !== null);
  return {
    isLastFrame,
    opcode,
    mask,
    payload,
  };
}
async function readFrame ( buf ) { let b = await buf . readByte ( ) ; assert ( b !== null ) ; let isLastFrame = false ; switch ( b >>> 4 ) { case 8 : isLastFrame = true ; break ; case 0 : isLastFrame = false ; break ; default : throw new Error ( "invalid signature" ) ; } const opcode = b & 15 ; b = await buf . readByte ( ) ; assert ( b !== null ) ; const hasMask = b >>> 7 ; let payloadLength = b & 127 ; if ( payloadLength === 126 ) { const l = await readShort ( buf ) ; assert ( l !== null ) ; payloadLength = l ; } else if ( payloadLength === 127 ) { const l = await readLong ( buf ) ; assert ( l !== null ) ; payloadLength = Number ( l ) ; } let mask ; if ( hasMask ) { mask = new Uint8Array ( 4 ) ; assert ( await buf . readFull ( mask ) !== null ) ; } const payload = new Uint8Array ( payloadLength ) ; assert ( await buf . readFull ( payload ) !== null ) ; return { isLastFrame , opcode , mask , payload , } ; }
Read websocket frame from given BufReader
 @throws `Deno.errors.UnexpectedEof` When peer closed connection without close frame
 @throws `Error` Frame is invalid
Read websocket frame from given BufReader @throws ` Deno . errors . UnexpectedEof ` When peer closed connection without close frame @throws ` Error ` Frame is invalid
// has_mask & payload // mask // payload