|
|
|
@ -13,21 +13,11 @@ |
|
|
|
|
#include "AutoConnectElementJson.h" |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set items common to any type of AutoConnectElement from JSON objects. |
|
|
|
|
* @param json JSON object with the definition of AutoConnectElement. |
|
|
|
|
*/ |
|
|
|
|
void AutoConnectElementJson::_setElement(const JsonObject& json) { |
|
|
|
|
name = json.get<String>(F(AUTOCONNECT_JSON_KEY_NAME)); |
|
|
|
|
value = json.get<String>(F(AUTOCONNECT_JSON_KEY_VALUE)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Serialize AutoConnectElement to JSON. |
|
|
|
|
* This function is base for each element. |
|
|
|
|
* @param json JSON object to be serialized. |
|
|
|
|
* Returns JSON object size. |
|
|
|
|
* @return An object size for JsonBuffer. |
|
|
|
|
*/ |
|
|
|
|
void AutoConnectElementJson::_serialize(JsonObject& json) { |
|
|
|
|
json.set(F(AUTOCONNECT_JSON_KEY_NAME), name); |
|
|
|
|
const size_t AutoConnectElementJson::getObjectSize() const { |
|
|
|
|
return JSON_OBJECT_SIZE(3); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -36,10 +26,10 @@ void AutoConnectElementJson::_serialize(JsonObject& json) { |
|
|
|
|
* @return true AutoConnectElement loaded |
|
|
|
|
* @return false Type of AutoConnectElement is mismatched. |
|
|
|
|
*/ |
|
|
|
|
bool AutoConnectElementJson::loadElement(const JsonObject& json) { |
|
|
|
|
bool AutoConnectElementJson::loadMember(const JsonObject& json) { |
|
|
|
|
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); |
|
|
|
|
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACELEMENT))) { |
|
|
|
|
_setElement(json); |
|
|
|
|
_setMember(json); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
@ -50,20 +40,47 @@ bool AutoConnectElementJson::loadElement(const JsonObject& json) { |
|
|
|
|
* @param json JSON object to be serialized. |
|
|
|
|
*/ |
|
|
|
|
void AutoConnectElementJson::serialize(JsonObject& json) { |
|
|
|
|
_serialize(json); |
|
|
|
|
json.set(F(AUTOCONNECT_JSON_KEY_TYPE), F(AUTOCONNECT_JSON_TYPE_ACELEMENT)); |
|
|
|
|
json.set(F(AUTOCONNECT_JSON_KEY_VALUE), value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Serialize AutoConnectElement to JSON. |
|
|
|
|
* This function is base for each element. |
|
|
|
|
* @param json JSON object to be serialized. |
|
|
|
|
*/ |
|
|
|
|
void AutoConnectElementJson::_serialize(JsonObject& json) { |
|
|
|
|
json.set(F(AUTOCONNECT_JSON_KEY_NAME), name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set items common to any type of AutoConnectElement from JSON objects. |
|
|
|
|
* @param json JSON object with the definition of AutoConnectElement. |
|
|
|
|
*/ |
|
|
|
|
void AutoConnectElementJson::_setMember(const JsonObject& json) { |
|
|
|
|
name = json.get<String>(F(AUTOCONNECT_JSON_KEY_NAME)); |
|
|
|
|
value = json.get<String>(F(AUTOCONNECT_JSON_KEY_VALUE)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns JSON object size. |
|
|
|
|
* @return An object size for JsonBuffer. |
|
|
|
|
*/ |
|
|
|
|
const size_t AutoConnectButtonJson::getObjectSize() const { |
|
|
|
|
return AutoConnectElementJson::getObjectSize() + JSON_OBJECT_SIZE(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load a button element attribute member from the JSON object. |
|
|
|
|
* @param json JSON object with the definition of AutoConnectElement. |
|
|
|
|
* @return true AutoConnectElement loaded |
|
|
|
|
* @return false Type of AutoConnectElement is mismatched. |
|
|
|
|
*/ |
|
|
|
|
bool AutoConnectButtonJson::loadElement(const JsonObject& json) { |
|
|
|
|
bool AutoConnectButtonJson::loadMember(const JsonObject& json) { |
|
|
|
|
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); |
|
|
|
|
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACBUTTON))) { |
|
|
|
|
_setElement(json); |
|
|
|
|
_setMember(json); |
|
|
|
|
action = json.get<String>(F(AUTOCONNECT_JSON_KEY_ACTION)); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -81,16 +98,24 @@ void AutoConnectButtonJson::serialize(JsonObject& json) { |
|
|
|
|
json.set(F(AUTOCONNECT_JSON_KEY_ACTION), action); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns JSON object size. |
|
|
|
|
* @return An object size for JsonBuffer. |
|
|
|
|
*/ |
|
|
|
|
const size_t AutoConnectCheckboxJson::getObjectSize() const { |
|
|
|
|
return AutoConnectElementJson::getObjectSize() + JSON_OBJECT_SIZE(2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load a checkbox element attribute member from the JSON object. |
|
|
|
|
* @param json JSON object with the definition of AutoConnectElement. |
|
|
|
|
* @return true AutoConnectElement loaded |
|
|
|
|
* @return false Type of AutoConnectElement is mismatched. |
|
|
|
|
*/ |
|
|
|
|
bool AutoConnectCheckboxJson::loadElement(const JsonObject& json) { |
|
|
|
|
bool AutoConnectCheckboxJson::loadMember(const JsonObject& json) { |
|
|
|
|
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); |
|
|
|
|
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACCHECKBOX))) { |
|
|
|
|
_setElement(json); |
|
|
|
|
_setMember(json); |
|
|
|
|
label = json.get<String>(F(AUTOCONNECT_JSON_KEY_LABEL)); |
|
|
|
|
checked = json.get<bool>(F(AUTOCONNECT_JSON_KEY_CHECKED)); |
|
|
|
|
return true; |
|
|
|
@ -111,16 +136,24 @@ void AutoConnectCheckboxJson::serialize(JsonObject& json) { |
|
|
|
|
json.set(F(AUTOCONNECT_JSON_KEY_CHECKED), checked); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns JSON object size. |
|
|
|
|
* @return An object size for JsonBuffer. |
|
|
|
|
*/ |
|
|
|
|
const size_t AutoConnectInputJson::getObjectSize() const { |
|
|
|
|
return AutoConnectElementJson::getObjectSize() + JSON_OBJECT_SIZE(2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load a input-box element attribute member from the JSON object. |
|
|
|
|
* @param json JSON object with the definition of AutoConnectElement. |
|
|
|
|
* @return true AutoConnectElement loaded |
|
|
|
|
* @return false Type of AutoConnectElement is mismatched. |
|
|
|
|
*/ |
|
|
|
|
bool AutoConnectInputJson::loadElement(const JsonObject& json) { |
|
|
|
|
bool AutoConnectInputJson::loadMember(const JsonObject& json) { |
|
|
|
|
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); |
|
|
|
|
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACINPUT))) { |
|
|
|
|
_setElement(json); |
|
|
|
|
_setMember(json); |
|
|
|
|
placeholder = json.get<String>(F(AUTOCONNECT_JSON_KEY_PLACEHOLDER)); |
|
|
|
|
label = json.get<String>(F(AUTOCONNECT_JSON_KEY_LABEL)); |
|
|
|
|
return true; |
|
|
|
@ -141,15 +174,23 @@ void AutoConnectInputJson::serialize(JsonObject& json) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load a radio-button element attribute member from the JSON object. |
|
|
|
|
* @param json JSON object with the definition of AutoConnectElement. |
|
|
|
|
* @return true AutoConnectElement loaded |
|
|
|
|
* @return false Type of AutoConnectElement is mismatched. |
|
|
|
|
*/ |
|
|
|
|
bool AutoConnectRadioJson::loadElement(const JsonObject& json) { |
|
|
|
|
* Returns JSON object size. |
|
|
|
|
* @return An object size for JsonBuffer. |
|
|
|
|
*/ |
|
|
|
|
const size_t AutoConnectRadioJson::getObjectSize() const { |
|
|
|
|
return AutoConnectElementJson::getObjectSize() + JSON_OBJECT_SIZE(3) + _values.size() * JSON_OBJECT_SIZE(1) + JSON_ARRAY_SIZE(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load a radio-button element attribute member from the JSON object. |
|
|
|
|
* @param json JSON object with the definition of AutoConnectElement. |
|
|
|
|
* @return true AutoConnectElement loaded |
|
|
|
|
* @return false Type of AutoConnectElement is mismatched. |
|
|
|
|
*/ |
|
|
|
|
bool AutoConnectRadioJson::loadMember(const JsonObject& json) { |
|
|
|
|
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); |
|
|
|
|
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACRADIO))) { |
|
|
|
|
_setElement(json); |
|
|
|
|
_setMember(json); |
|
|
|
|
label = json.get<String>(F(AUTOCONNECT_JSON_KEY_LABEL)); |
|
|
|
|
checked = static_cast<uint8_t>(json.get<int>(F(AUTOCONNECT_JSON_KEY_CHECKED))); |
|
|
|
|
String arrange = json.get<String>(F(AUTOCONNECT_JSON_KEY_ARRANGE)); |
|
|
|
@ -188,16 +229,24 @@ void AutoConnectRadioJson::serialize(JsonObject& json) { |
|
|
|
|
json.set(F(AUTOCONNECT_JSON_KEY_CHECKED), checked); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns JSON object size. |
|
|
|
|
* @return An object size for JsonBuffer. |
|
|
|
|
*/ |
|
|
|
|
const size_t AutoConnectSelectJson::getObjectSize() const { |
|
|
|
|
return AutoConnectElementJson::getObjectSize() + JSON_OBJECT_SIZE(3) + _options.size() * JSON_OBJECT_SIZE(1) + JSON_ARRAY_SIZE(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load a select element attribute member from the JSON object. |
|
|
|
|
* @param json JSON object with the definition of AutoConnectElement. |
|
|
|
|
* @return true AutoConnectElement loaded |
|
|
|
|
* @return false Type of AutoConnectElement is mismatched. |
|
|
|
|
*/ |
|
|
|
|
bool AutoConnectSelectJson::loadElement(const JsonObject& json) { |
|
|
|
|
bool AutoConnectSelectJson::loadMember(const JsonObject& json) { |
|
|
|
|
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); |
|
|
|
|
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACSELECT))) { |
|
|
|
|
_setElement(json); |
|
|
|
|
_setMember(json); |
|
|
|
|
label = json.get<String>(F(AUTOCONNECT_JSON_KEY_LABEL)); |
|
|
|
|
empty(); |
|
|
|
|
JsonArray& optionArray = json[AUTOCONNECT_JSON_KEY_OPTION]; |
|
|
|
@ -221,16 +270,24 @@ void AutoConnectSelectJson::serialize(JsonObject& json) { |
|
|
|
|
json.set(F(AUTOCONNECT_JSON_KEY_LABEL), label); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns JSON object size. |
|
|
|
|
* @return An object size for JsonBuffer. |
|
|
|
|
*/ |
|
|
|
|
const size_t AutoConnectSubmitJson::getObjectSize() const { |
|
|
|
|
return AutoConnectElementJson::getObjectSize() + JSON_OBJECT_SIZE(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load a submit element attribute member from the JSON object. |
|
|
|
|
* @param json JSON object with the definition of AutoConnectElement. |
|
|
|
|
* @return true AutoConnectElement loaded |
|
|
|
|
* @return false Type of AutoConnectElement is mismatched. |
|
|
|
|
*/ |
|
|
|
|
bool AutoConnectSubmitJson::loadElement(const JsonObject& json) { |
|
|
|
|
bool AutoConnectSubmitJson::loadMember(const JsonObject& json) { |
|
|
|
|
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); |
|
|
|
|
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACSUBMIT))) { |
|
|
|
|
_setElement(json); |
|
|
|
|
_setMember(json); |
|
|
|
|
uri = json.get<String>(F(AUTOCONNECT_JSON_KEY_URI)); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -248,16 +305,24 @@ void AutoConnectSubmitJson::serialize(JsonObject& json) { |
|
|
|
|
json.set(F(AUTOCONNECT_JSON_KEY_URI), uri); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns JSON object size. |
|
|
|
|
* @return An object size for JsonBuffer. |
|
|
|
|
*/ |
|
|
|
|
const size_t AutoConnectTextJson::getObjectSize() const { |
|
|
|
|
return AutoConnectElementJson::getObjectSize() + JSON_OBJECT_SIZE(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load a text element attribute member from the JSON object. |
|
|
|
|
* @param json JSON object with the definition of AutoConnectElement. |
|
|
|
|
* @return true AutoConnectElement loaded |
|
|
|
|
* @return false Type of AutoConnectElement is mismatched. |
|
|
|
|
*/ |
|
|
|
|
bool AutoConnectTextJson::loadElement(const JsonObject& json) { |
|
|
|
|
bool AutoConnectTextJson::loadMember(const JsonObject& json) { |
|
|
|
|
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); |
|
|
|
|
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACTEXT))) { |
|
|
|
|
_setElement(json); |
|
|
|
|
_setMember(json); |
|
|
|
|
style = json.get<String>(F(AUTOCONNECT_JSON_KEY_STYLE)); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|