Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
WebsocketFrameClass Class Reference

Websocket Frame. More...

#include <WebsocketFrame.h>

Public Member Functions

uint8_t encodeFrame (WSFrameType frameType, uint8_t *payload, size_t length, uint8_t mask, uint8_t fin, uint8_t headerToPayload=true)
 
uint8_t decodeFrame (uint8_t *buffer, size_t length)
 Encode given buffer to valid websocket frame. More...
 

Protected Member Functions

uint8_t _getFrameSizes (uint8_t *buffer, size_t length)
 

Protected Attributes

uint8_t * _payload = nullptr
 Decode given buffer containing websocket frame to payload. More...
 
size_t _payloadLength = 0
 
uint8_t * _header = nullptr
 
size_t _headerLength = 0
 
WSFrameType _frameType = WSFrameType::empty
 
uint8_t _mask = 0
 

Friends

class HttpServer
 
class Websocket
 
class WebsocketClient
 

Detailed Description

Websocket Frame.

Member Function Documentation

uint8_t WebsocketFrameClass::decodeFrame ( uint8_t *  buffer,
size_t  length 
)

Encode given buffer to valid websocket frame.

Parameters
frameTypeWebsocket frame type text or binary
payloadPointer to buffer to be encoded as websocket frame
lengthLength of buffer to be encoded as websocket frame
maskIf true websocket frame will be masked (required for client->server communication)
finIf true produce ordinary websocket frame, not continuation. Currently MUST be true.
headerToPayloadIf true try to create single buffer message with header and payload, otherwise produce separate header and payload buffers
Return values
Returntrue on success, false on error

if successfully executed, check whether _header is not nullptr and either use _header and _payload or just _payload as websocket frame

Member Data Documentation

uint8_t* WebsocketFrameClass::_payload = nullptr
protected

Decode given buffer containing websocket frame to payload.

Parameters
bufferPointer to buffer to be decoded as websocket frame
lengthLength of buffer to be decoded as websocket frame
Return values
Returntrue on success, false on error

if successfully executed, check _frameType to decide what to do with payload pointed by _payload