mirror of
https://github.com/esphome/esphome.git
synced 2024-12-01 11:14:13 +01:00
Fix linting issues
This commit is contained in:
parent
4e4cdc92a1
commit
7942ec4e70
12 changed files with 74 additions and 69 deletions
|
@ -10,6 +10,7 @@ from esphome.const import (
|
||||||
DEVICE_CLASS_SIGNAL_STRENGTH,
|
DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||||
STATE_CLASS_MEASUREMENT,
|
STATE_CLASS_MEASUREMENT,
|
||||||
UNIT_DECIBEL_MILLIWATT,
|
UNIT_DECIBEL_MILLIWATT,
|
||||||
|
CONF_NOTIFY,
|
||||||
)
|
)
|
||||||
from esphome import automation
|
from esphome import automation
|
||||||
from .. import ble_client_ns
|
from .. import ble_client_ns
|
||||||
|
@ -18,7 +19,6 @@ DEPENDENCIES = ["ble_client"]
|
||||||
|
|
||||||
CONF_DESCRIPTOR_UUID = "descriptor_uuid"
|
CONF_DESCRIPTOR_UUID = "descriptor_uuid"
|
||||||
|
|
||||||
CONF_NOTIFY = "notify"
|
|
||||||
CONF_ON_NOTIFY = "on_notify"
|
CONF_ON_NOTIFY = "on_notify"
|
||||||
TYPE_CHARACTERISTIC = "characteristic"
|
TYPE_CHARACTERISTIC = "characteristic"
|
||||||
TYPE_RSSI = "rssi"
|
TYPE_RSSI = "rssi"
|
||||||
|
|
|
@ -6,6 +6,7 @@ from esphome.const import (
|
||||||
CONF_ID,
|
CONF_ID,
|
||||||
CONF_TRIGGER_ID,
|
CONF_TRIGGER_ID,
|
||||||
CONF_SERVICE_UUID,
|
CONF_SERVICE_UUID,
|
||||||
|
CONF_NOTIFY,
|
||||||
)
|
)
|
||||||
from esphome import automation
|
from esphome import automation
|
||||||
from .. import ble_client_ns
|
from .. import ble_client_ns
|
||||||
|
@ -14,7 +15,6 @@ DEPENDENCIES = ["ble_client"]
|
||||||
|
|
||||||
CONF_DESCRIPTOR_UUID = "descriptor_uuid"
|
CONF_DESCRIPTOR_UUID = "descriptor_uuid"
|
||||||
|
|
||||||
CONF_NOTIFY = "notify"
|
|
||||||
CONF_ON_NOTIFY = "on_notify"
|
CONF_ON_NOTIFY = "on_notify"
|
||||||
|
|
||||||
adv_data_t = cg.std_vector.template(cg.uint8)
|
adv_data_t = cg.std_vector.template(cg.uint8)
|
||||||
|
|
|
@ -7,6 +7,7 @@ from esphome.const import (
|
||||||
CONF_UUID,
|
CONF_UUID,
|
||||||
CONF_SERVICES,
|
CONF_SERVICES,
|
||||||
CONF_VALUE,
|
CONF_VALUE,
|
||||||
|
CONF_NOTIFY,
|
||||||
)
|
)
|
||||||
from esphome.components import esp32_ble
|
from esphome.components import esp32_ble
|
||||||
from esphome.core import CORE
|
from esphome.core import CORE
|
||||||
|
@ -25,12 +26,11 @@ CONF_ON_WRITE = "on_write"
|
||||||
CONF_CHARACTERISTICS = "characteristics"
|
CONF_CHARACTERISTICS = "characteristics"
|
||||||
CONF_READ = "read"
|
CONF_READ = "read"
|
||||||
CONF_WRITE = "write"
|
CONF_WRITE = "write"
|
||||||
CONF_NOTIFY = "notify"
|
|
||||||
CONF_BROADCAST = "broadcast"
|
CONF_BROADCAST = "broadcast"
|
||||||
CONF_INDICATE = "indicate"
|
CONF_INDICATE = "indicate"
|
||||||
CONF_WRITE_NO_RESPONSE = "write_no_response"
|
CONF_WRITE_NO_RESPONSE = "write_no_response"
|
||||||
CONF_DESCRIPTORS = "descriptors"
|
CONF_DESCRIPTORS = "descriptors"
|
||||||
CONF_VALUE_ACTION_ID = "value_action_id_"
|
CONF_VALUE_ACTION_ID_ = "value_action_id_"
|
||||||
|
|
||||||
esp32_ble_server_ns = cg.esphome_ns.namespace("esp32_ble_server")
|
esp32_ble_server_ns = cg.esphome_ns.namespace("esp32_ble_server")
|
||||||
ESPBTUUID_ns = cg.esphome_ns.namespace("esp32_ble").namespace("ESPBTUUID")
|
ESPBTUUID_ns = cg.esphome_ns.namespace("esp32_ble").namespace("ESPBTUUID")
|
||||||
|
@ -106,7 +106,9 @@ SERVICE_CHARACTERISTIC_SCHEMA = cv.Schema(
|
||||||
cv.Optional(CONF_INDICATE, default=False): cv.boolean,
|
cv.Optional(CONF_INDICATE, default=False): cv.boolean,
|
||||||
cv.Optional(CONF_WRITE_NO_RESPONSE, default=False): cv.boolean,
|
cv.Optional(CONF_WRITE_NO_RESPONSE, default=False): cv.boolean,
|
||||||
cv.Optional(CONF_VALUE): CHARACTERISTIC_VALUE_SCHEMA,
|
cv.Optional(CONF_VALUE): CHARACTERISTIC_VALUE_SCHEMA,
|
||||||
cv.GenerateID(CONF_VALUE_ACTION_ID): cv.declare_id(BLECharacteristicSetValueAction),
|
cv.GenerateID(CONF_VALUE_ACTION_ID): cv.declare_id(
|
||||||
|
BLECharacteristicSetValueAction
|
||||||
|
),
|
||||||
cv.Optional(CONF_DESCRIPTORS, default=[]): cv.ensure_list(
|
cv.Optional(CONF_DESCRIPTORS, default=[]): cv.ensure_list(
|
||||||
DESCRIPTOR_SCHEMA
|
DESCRIPTOR_SCHEMA
|
||||||
),
|
),
|
||||||
|
@ -205,7 +207,10 @@ def parse_descriptor_value(value):
|
||||||
return value, value_len
|
return value, value_len
|
||||||
except cv.Invalid:
|
except cv.Invalid:
|
||||||
pass
|
pass
|
||||||
return cg.std_vector.template(cg.uint8)(value), len(value) # Assume it's a list of bytes
|
return (
|
||||||
|
cg.std_vector.template(cg.uint8)(value),
|
||||||
|
len(value),
|
||||||
|
) # Assume it's a list of bytes
|
||||||
|
|
||||||
|
|
||||||
def calculate_num_handles(service_config):
|
def calculate_num_handles(service_config):
|
||||||
|
@ -268,7 +273,7 @@ async def to_code(config):
|
||||||
CONF_ID: char_conf[CONF_ID],
|
CONF_ID: char_conf[CONF_ID],
|
||||||
CONF_VALUE: char_conf[CONF_VALUE],
|
CONF_VALUE: char_conf[CONF_VALUE],
|
||||||
}
|
}
|
||||||
value_action = await ble_server_characteristic_set_value(action_conf, char_conf[CONF_VALUE_ACTION_ID], cg.TemplateArguments(None), {})
|
value_action = await ble_server_characteristic_set_value(action_conf, char_conf[CONF_VALUE_ACTION_ID_], cg.TemplateArguments(None), {})
|
||||||
cg.add(value_action.play())
|
cg.add(value_action.play())
|
||||||
for descriptor_conf in char_conf[CONF_DESCRIPTORS]:
|
for descriptor_conf in char_conf[CONF_DESCRIPTORS]:
|
||||||
descriptor_value, max_length = parse_descriptor_value(descriptor_conf[CONF_VALUE])
|
descriptor_value, max_length = parse_descriptor_value(descriptor_conf[CONF_VALUE])
|
||||||
|
@ -291,20 +296,19 @@ async def parse_characteristic_value(value, args):
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
return cg.std_vector.template(cg.uint8)(value)
|
return cg.std_vector.template(cg.uint8)(value)
|
||||||
# Transform the value into a vector of bytes
|
# Transform the value into a vector of bytes
|
||||||
exp_value = cg.RawExpression(f'to_vector({value})')
|
|
||||||
try:
|
try:
|
||||||
bool_value = cv.boolean(value)
|
bool_value = cv.boolean(value)
|
||||||
return cg.RawExpression(f'to_vector({"true" if bool_value else "false"})')
|
return cg.RawExpression(f"to_vector({'true' if bool_value else 'false'})")
|
||||||
except cv.Invalid:
|
except cv.Invalid:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
int_ = cv.uint64_t(value)
|
int_ = cv.uint64_t(value)
|
||||||
return cg.RawExpression(f'to_vector({int_})')
|
return cg.RawExpression(f"to_vector({int_})")
|
||||||
except cv.Invalid:
|
except cv.Invalid:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
float_ = cv.float_(value)
|
float_ = cv.float_(value)
|
||||||
return cg.RawExpression(f'to_vector({float_})')
|
return cg.RawExpression(f"to_vector({float_})")
|
||||||
except cv.Invalid:
|
except cv.Invalid:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
|
@ -312,7 +316,7 @@ async def parse_characteristic_value(value, args):
|
||||||
return cg.RawExpression(f'to_vector("{string_}")')
|
return cg.RawExpression(f'to_vector("{string_}")')
|
||||||
except cv.Invalid:
|
except cv.Invalid:
|
||||||
pass
|
pass
|
||||||
raise cv.Invalid(f"Invalid value {value}")
|
raise cv.Invalid(f"Could not find type for value: {value}")
|
||||||
|
|
||||||
|
|
||||||
@automation.register_action(
|
@automation.register_action(
|
||||||
|
@ -350,7 +354,9 @@ async def ble_server_characteristic_notify(config, action_id, template_arg, args
|
||||||
for char_conf in service_config[CONF_CHARACTERISTICS]:
|
for char_conf in service_config[CONF_CHARACTERISTICS]:
|
||||||
if char_conf[CONF_ID] == config[CONF_ID]:
|
if char_conf[CONF_ID] == config[CONF_ID]:
|
||||||
if not char_conf[CONF_NOTIFY]:
|
if not char_conf[CONF_NOTIFY]:
|
||||||
raise cv.Invalid(f'Characteristic "{char_conf[CONF_ID]}" does not have the NOTIFY property set')
|
raise cv.Invalid(
|
||||||
|
f'Characteristic "{char_conf[CONF_ID]}" does not have the NOTIFY property set'
|
||||||
|
)
|
||||||
break
|
break
|
||||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||||
return var
|
return var
|
||||||
|
|
|
@ -248,7 +248,8 @@ void BLECharacteristic::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!param->write.is_prep) {
|
if (!param->write.is_prep) {
|
||||||
this->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>>::emit(BLECharacteristicEvt::VectorEvt::ON_WRITE, this->value_);
|
this->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>>::emit(
|
||||||
|
BLECharacteristicEvt::VectorEvt::ON_WRITE, this->value_);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -259,7 +260,8 @@ void BLECharacteristic::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt
|
||||||
break;
|
break;
|
||||||
this->write_event_ = false;
|
this->write_event_ = false;
|
||||||
if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_EXEC) {
|
if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_EXEC) {
|
||||||
this->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>>::emit(BLECharacteristicEvt::VectorEvt::ON_WRITE, this->value_);
|
this->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>>::emit(
|
||||||
|
BLECharacteristicEvt::VectorEvt::ON_WRITE, this->value_);
|
||||||
}
|
}
|
||||||
esp_err_t err =
|
esp_err_t err =
|
||||||
esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, ESP_GATT_OK, nullptr);
|
esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, ESP_GATT_OK, nullptr);
|
||||||
|
|
|
@ -34,7 +34,8 @@ namespace BLECharacteristicEvt {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class BLECharacteristic : public EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>>, public EventEmitter<BLECharacteristicEvt::EmptyEvt> {
|
class BLECharacteristic : public EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>>,
|
||||||
|
public EventEmitter<BLECharacteristicEvt::EmptyEvt> {
|
||||||
public:
|
public:
|
||||||
BLECharacteristic(ESPBTUUID uuid, uint32_t properties);
|
BLECharacteristic(ESPBTUUID uuid, uint32_t properties);
|
||||||
~BLECharacteristic();
|
~BLECharacteristic();
|
||||||
|
|
|
@ -10,18 +10,21 @@ namespace esp32_ble_server_automations {
|
||||||
using namespace esp32_ble;
|
using namespace esp32_ble;
|
||||||
|
|
||||||
Trigger<std::vector<uint8_t>> *BLETriggers::create_on_write_trigger(BLECharacteristic *characteristic) {
|
Trigger<std::vector<uint8_t>> *BLETriggers::create_on_write_trigger(BLECharacteristic *characteristic) {
|
||||||
Trigger<std::vector<uint8_t>> *on_write_trigger = new Trigger<std::vector<uint8_t>>(); // NOLINT(cppcoreguidelines-owning-memory)
|
Trigger<std::vector<uint8_t>> *on_write_trigger =
|
||||||
characteristic->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>>::on(BLECharacteristicEvt::VectorEvt::ON_WRITE, [on_write_trigger](const std::vector<uint8_t> &data) {
|
new Trigger<std::vector<uint8_t>>(); // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
on_write_trigger->trigger(data);
|
characteristic->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>>::on(
|
||||||
});
|
BLECharacteristicEvt::VectorEvt::ON_WRITE,
|
||||||
|
[on_write_trigger](const std::vector<uint8_t> &data) { on_write_trigger->trigger(data); });
|
||||||
return on_write_trigger;
|
return on_write_trigger;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BLECharacteristicSetValueActionManager::set_listener(BLECharacteristic *characteristic, EventEmitterListenerID listener_id) {
|
void BLECharacteristicSetValueActionManager::set_listener(BLECharacteristic *characteristic,
|
||||||
|
EventEmitterListenerID listener_id) {
|
||||||
// Check if there is already a listener for this characteristic
|
// Check if there is already a listener for this characteristic
|
||||||
if (this->listeners_.find(characteristic) != this->listeners_.end()) {
|
if (this->listeners_.find(characteristic) != this->listeners_.end()) {
|
||||||
// Remove the previous listener
|
// Remove the previous listener
|
||||||
characteristic->EventEmitter<BLECharacteristicEvt::EmptyEvt>::off(BLECharacteristicEvt::EmptyEvt::ON_READ, this->listeners_[characteristic]);
|
characteristic->EventEmitter<BLECharacteristicEvt::EmptyEvt>::off(BLECharacteristicEvt::EmptyEvt::ON_READ,
|
||||||
|
this->listeners_[characteristic]);
|
||||||
}
|
}
|
||||||
this->listeners_[characteristic] = listener_id;
|
this->listeners_[characteristic] = listener_id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,8 @@ template<typename... Ts> class BLECharacteristicSetValueAction : public Action<T
|
||||||
// Set initial value
|
// Set initial value
|
||||||
this->parent_->set_value(this->value_.value(x...));
|
this->parent_->set_value(this->value_.value(x...));
|
||||||
// Set the listener for read events
|
// Set the listener for read events
|
||||||
this->listener_id_ = this->parent_->EventEmitter<BLECharacteristicEvt::EmptyEvt>::on(BLECharacteristicEvt::EmptyEvt::ON_READ, [this, x...](void) {
|
this->listener_id_ = this->parent_->EventEmitter<BLECharacteristicEvt::EmptyEvt>::on(
|
||||||
|
BLECharacteristicEvt::EmptyEvt::ON_READ, [this, x...](void) {
|
||||||
// Set the value of the characteristic every time it is read
|
// Set the value of the characteristic every time it is read
|
||||||
this->parent_->set_value(this->value_.value(x...));
|
this->parent_->set_value(this->value_.value(x...));
|
||||||
});
|
});
|
||||||
|
|
|
@ -40,7 +40,8 @@ void ESP32ImprovComponent::setup_characteristics() {
|
||||||
this->error_->add_descriptor(error_descriptor);
|
this->error_->add_descriptor(error_descriptor);
|
||||||
|
|
||||||
this->rpc_ = this->service_->create_characteristic(improv::RPC_COMMAND_UUID, BLECharacteristic::PROPERTY_WRITE);
|
this->rpc_ = this->service_->create_characteristic(improv::RPC_COMMAND_UUID, BLECharacteristic::PROPERTY_WRITE);
|
||||||
this->rpc_->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>>::on(BLECharacteristicEvt::VectorEvt::ON_WRITE, [this](const std::vector<uint8_t> &data) {
|
this->rpc_->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>>::on(
|
||||||
|
BLECharacteristicEvt::VectorEvt::ON_WRITE, [this](const std::vector<uint8_t> &data) {
|
||||||
if (!data.empty()) {
|
if (!data.empty()) {
|
||||||
this->incoming_data_.insert(this->incoming_data_.end(), data.begin(), data.end());
|
this->incoming_data_.insert(this->incoming_data_.end(), data.begin(), data.end());
|
||||||
}
|
}
|
||||||
|
|
|
@ -509,6 +509,7 @@ CONF_NEC = "nec"
|
||||||
CONF_NETWORKS = "networks"
|
CONF_NETWORKS = "networks"
|
||||||
CONF_NEW_PASSWORD = "new_password"
|
CONF_NEW_PASSWORD = "new_password"
|
||||||
CONF_NOISE_LEVEL = "noise_level"
|
CONF_NOISE_LEVEL = "noise_level"
|
||||||
|
CONF_NOTIFY = "notify"
|
||||||
CONF_NUM_ATTEMPTS = "num_attempts"
|
CONF_NUM_ATTEMPTS = "num_attempts"
|
||||||
CONF_NUM_CHANNELS = "num_channels"
|
CONF_NUM_CHANNELS = "num_channels"
|
||||||
CONF_NUM_CHIPS = "num_chips"
|
CONF_NUM_CHIPS = "num_chips"
|
||||||
|
|
|
@ -9,15 +9,13 @@ namespace esphome {
|
||||||
|
|
||||||
using EventEmitterListenerID = uint32_t;
|
using EventEmitterListenerID = uint32_t;
|
||||||
|
|
||||||
// EventEmitter class that can emit events with a specific name (usually an enum) and a list of arguments.
|
// EventEmitter class that can emit events with a specific name (it is highly recommended to use an enum class for this) and a list of arguments.
|
||||||
// Supports multiple listeners for each event.
|
// Supports multiple listeners for each event.
|
||||||
template <typename EvtNames, typename... Args>
|
template <typename EvtNames, typename... Args>
|
||||||
class EventEmitter {
|
class EventEmitter {
|
||||||
public:
|
public:
|
||||||
EventEmitterListenerID on(EvtNames event, std::function<void(Args...)> listener) {
|
EventEmitterListenerID on(EvtNames event, std::function<void(Args...)> listener) {
|
||||||
listeners_[event].emplace_back(++current_id_, [listener](Args... args) {
|
listeners_[event].emplace_back(++current_id_, [listener](Args... args) { listener(args...); });
|
||||||
listener(args...);
|
|
||||||
});
|
|
||||||
return current_id_;
|
return current_id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,9 +23,11 @@ class EventEmitter {
|
||||||
if (this->listeners_.count(event) == 0)
|
if (this->listeners_.count(event) == 0)
|
||||||
return;
|
return;
|
||||||
auto &vec = this->listeners_[event];
|
auto &vec = this->listeners_[event];
|
||||||
vec.erase(std::remove_if(vec.begin(), vec.end(), [id](const std::pair<EventEmitterListenerID, std::function<void(Args...)>> &pair) {
|
vec.erase(std::remove_if(vec.begin(), vec.end(),
|
||||||
|
[id](const std::pair<EventEmitterListenerID, std::function<void(Args...)>> &pair) {
|
||||||
return pair.first == id;
|
return pair.first == id;
|
||||||
}), vec.end());
|
}),
|
||||||
|
vec.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -536,9 +536,7 @@ std::vector<uint8_t> base64_decode(const std::string &encoded_string) {
|
||||||
|
|
||||||
std::vector<uint8_t> to_vector(bool value) { return {value ? (uint8_t)1 : (uint8_t)0}; }
|
std::vector<uint8_t> to_vector(bool value) { return {value ? (uint8_t)1 : (uint8_t)0}; }
|
||||||
std::vector<uint8_t> to_vector(uint8_t value) { return {value}; }
|
std::vector<uint8_t> to_vector(uint8_t value) { return {value}; }
|
||||||
std::vector<uint8_t> to_vector(uint16_t value) {
|
std::vector<uint8_t> to_vector(uint16_t value) { return {uint8_t(value >> 8), uint8_t(value & 0xFF)}; }
|
||||||
return {uint8_t(value >> 8), uint8_t(value & 0xFF)};
|
|
||||||
}
|
|
||||||
std::vector<uint8_t> to_vector(uint32_t value) {
|
std::vector<uint8_t> to_vector(uint32_t value) {
|
||||||
return {uint8_t(value >> 24), uint8_t((value >> 16) & 0xFF), uint8_t((value >> 8) & 0xFF), uint8_t(value & 0xFF)};
|
return {uint8_t(value >> 24), uint8_t((value >> 16) & 0xFF), uint8_t((value >> 8) & 0xFF), uint8_t(value & 0xFF)};
|
||||||
}
|
}
|
||||||
|
@ -547,18 +545,10 @@ std::vector<uint8_t> to_vector(uint64_t value) {
|
||||||
uint8_t((value >> 32) & 0xFF), uint8_t((value >> 24) & 0xFF), uint8_t((value >> 16) & 0xFF),
|
uint8_t((value >> 32) & 0xFF), uint8_t((value >> 24) & 0xFF), uint8_t((value >> 16) & 0xFF),
|
||||||
uint8_t((value >> 8) & 0xFF), uint8_t(value & 0xFF)};
|
uint8_t((value >> 8) & 0xFF), uint8_t(value & 0xFF)};
|
||||||
}
|
}
|
||||||
std::vector<uint8_t> to_vector(int value) {
|
std::vector<uint8_t> to_vector(int value) { return to_vector(static_cast<uint32_t>(value)); }
|
||||||
return to_vector(static_cast<uint32_t>(value));
|
std::vector<uint8_t> to_vector(float value) { return to_vector(*reinterpret_cast<uint32_t *>(&value)); }
|
||||||
}
|
std::vector<uint8_t> to_vector(double value) { return to_vector(*reinterpret_cast<uint64_t *>(&value)); }
|
||||||
std::vector<uint8_t> to_vector(float value) {
|
std::vector<uint8_t> to_vector(const std::string &value) { return std::vector<uint8_t>(value.begin(), value.end()); }
|
||||||
return to_vector(*reinterpret_cast<uint32_t *>(&value));
|
|
||||||
}
|
|
||||||
std::vector<uint8_t> to_vector(double value) {
|
|
||||||
return to_vector(*reinterpret_cast<uint64_t *>(&value));
|
|
||||||
}
|
|
||||||
std::vector<uint8_t> to_vector(const std::string &value) {
|
|
||||||
return std::vector<uint8_t>(value.begin(), value.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Colors
|
// Colors
|
||||||
|
|
||||||
|
|
|
@ -441,7 +441,7 @@ std::string base64_encode(const std::vector<uint8_t> &buf);
|
||||||
std::vector<uint8_t> base64_decode(const std::string &encoded_string);
|
std::vector<uint8_t> base64_decode(const std::string &encoded_string);
|
||||||
size_t base64_decode(std::string const &encoded_string, uint8_t *buf, size_t buf_len);
|
size_t base64_decode(std::string const &encoded_string, uint8_t *buf, size_t buf_len);
|
||||||
|
|
||||||
/// Create a byte vector multiple types of values.
|
/// Create a byte vector from multiple types of values.
|
||||||
std::vector<uint8_t> to_vector(bool value);
|
std::vector<uint8_t> to_vector(bool value);
|
||||||
std::vector<uint8_t> to_vector(uint8_t value);
|
std::vector<uint8_t> to_vector(uint8_t value);
|
||||||
std::vector<uint8_t> to_vector(uint16_t value);
|
std::vector<uint8_t> to_vector(uint16_t value);
|
||||||
|
|
Loading…
Reference in a new issue