mirror of
https://github.com/s00500/ESPUI.git
synced 2024-11-23 16:00:54 +00:00
Added mechanism to estimate the marshaled size of a control.
This commit is contained in:
parent
6dcaf55c84
commit
f472dc1158
@ -19,6 +19,7 @@ Control::Control(ControlType type, const char* label, std::function<void(Control
|
|||||||
{
|
{
|
||||||
id = ++idCounter;
|
id = ++idCounter;
|
||||||
ControlChangeID = 1;
|
ControlChangeID = 1;
|
||||||
|
EstimateMarshaledSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
Control::Control(const Control& Control)
|
Control::Control(const Control& Control)
|
||||||
@ -31,7 +32,8 @@ Control::Control(const Control& Control)
|
|||||||
visible(Control.visible),
|
visible(Control.visible),
|
||||||
parentControl(Control.parentControl),
|
parentControl(Control.parentControl),
|
||||||
next(Control.next),
|
next(Control.next),
|
||||||
ControlChangeID(Control.ControlChangeID)
|
ControlChangeID(Control.ControlChangeID),
|
||||||
|
EstimatedMarshaledSize(Control.EstimatedMarshaledSize)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void Control::SendCallback(int type)
|
void Control::SendCallback(int type)
|
||||||
@ -281,3 +283,9 @@ void Control::onWsEvent(String & cmd, String& data)
|
|||||||
} while (false);
|
} while (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Control::EstimateMarshaledSize()
|
||||||
|
{
|
||||||
|
EstimatedMarshaledSize = MarshalingOverhead + (JsonMarshalingRatio * (strlen(label) + value.length()));
|
||||||
|
|
||||||
|
} // EstimateSerializedSize
|
||||||
|
|
||||||
|
@ -89,12 +89,20 @@ public:
|
|||||||
void onWsEvent(String& cmd, String& data);
|
void onWsEvent(String& cmd, String& data);
|
||||||
inline bool ToBeDeleted() { return _ToBeDeleted; }
|
inline bool ToBeDeleted() { return _ToBeDeleted; }
|
||||||
inline bool NeedsSync(uint32_t lastControlChangeID) {return (false == _ToBeDeleted) && (lastControlChangeID < ControlChangeID);}
|
inline bool NeedsSync(uint32_t lastControlChangeID) {return (false == _ToBeDeleted) && (lastControlChangeID < ControlChangeID);}
|
||||||
void SetControlChangedId(uint32_t value) {ControlChangeID = value;}
|
void SetControlChangedId(uint32_t value) {ControlChangeID = value; EstimateMarshaledSize();}
|
||||||
|
uint32_t GetEstimatedMarshaledSize() {return EstimatedMarshaledSize;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _ToBeDeleted = false;
|
bool _ToBeDeleted = false;
|
||||||
uint32_t ControlChangeID = 0;
|
uint32_t ControlChangeID = 0;
|
||||||
|
uint32_t EstimatedMarshaledSize = 0;
|
||||||
String OldValue = emptyString;
|
String OldValue = emptyString;
|
||||||
|
|
||||||
|
// multiplier for converting a typical controller label and value to a Json object
|
||||||
|
#define JsonMarshalingRatio 6
|
||||||
|
// estimated number of bytes for the fixed portion of a control rendered as Json
|
||||||
|
#define MarshalingOverhead 90
|
||||||
|
void EstimateMarshaledSize();
|
||||||
};
|
};
|
||||||
|
|
||||||
#define UI_TITLE ControlType::Title
|
#define UI_TITLE ControlType::Title
|
||||||
|
Loading…
Reference in New Issue
Block a user