mirror of https://github.com/arendst/Tasmota.git
Merge pull request #15741 from s-hadinger/berry_bytes_tohex
Berry bytes().tohex()
This commit is contained in:
commit
bb582191dd
|
@ -947,6 +947,7 @@ extern const bcstring be_const_str_timer_cb;
|
||||||
extern const bcstring be_const_str_to_gamma;
|
extern const bcstring be_const_str_to_gamma;
|
||||||
extern const bcstring be_const_str_tob64;
|
extern const bcstring be_const_str_tob64;
|
||||||
extern const bcstring be_const_str_tobytes;
|
extern const bcstring be_const_str_tobytes;
|
||||||
|
extern const bcstring be_const_str_tohex;
|
||||||
extern const bcstring be_const_str_toint;
|
extern const bcstring be_const_str_toint;
|
||||||
extern const bcstring be_const_str_tolower;
|
extern const bcstring be_const_str_tolower;
|
||||||
extern const bcstring be_const_str_tomap;
|
extern const bcstring be_const_str_tomap;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,43 +1,44 @@
|
||||||
#include "be_constobj.h"
|
#include "be_constobj.h"
|
||||||
|
|
||||||
static be_define_const_map_slots(be_class_bytes_map) {
|
static be_define_const_map_slots(be_class_bytes_map) {
|
||||||
{ be_const_key(_X2Esize, 9), be_const_var(0) },
|
{ be_const_key(set, -1), be_const_func(m_set) },
|
||||||
{ be_const_key(resize, -1), be_const_func(m_resize) },
|
{ be_const_key(_X2Elen, 0), be_const_var(0) },
|
||||||
|
{ be_const_key(tob64, 4), be_const_func(m_tob64) },
|
||||||
|
{ be_const_key(_X2E_X2E, -1), be_const_func(m_connect) },
|
||||||
|
{ be_const_key(setfloat, -1), be_const_func(m_setfloat) },
|
||||||
|
{ be_const_key(get, 2), be_const_func(m_getu) },
|
||||||
|
{ be_const_key(asstring, -1), be_const_func(m_asstring) },
|
||||||
|
{ be_const_key(getfloat, 24), be_const_func(m_getfloat) },
|
||||||
|
{ be_const_key(_buffer, -1), be_const_func(m_buffer) },
|
||||||
|
{ be_const_key(init, -1), be_const_func(m_init) },
|
||||||
|
{ be_const_key(_X2Esize, 23), be_const_var(1) },
|
||||||
|
{ be_const_key(tohex, 16), be_const_func(m_tohex) },
|
||||||
|
{ be_const_key(fromhex, -1), be_const_func(m_fromhex) },
|
||||||
|
{ be_const_key(setbits, 7), be_const_closure(setbits_closure) },
|
||||||
|
{ be_const_key(copy, 31), be_const_func(m_copy) },
|
||||||
|
{ be_const_key(size, 17), be_const_func(m_size) },
|
||||||
|
{ be_const_key(getbits, -1), be_const_closure(getbits_closure) },
|
||||||
|
{ be_const_key(fromb64, -1), be_const_func(m_fromb64) },
|
||||||
|
{ be_const_key(_change_buffer, -1), be_const_func(m_change_buffer) },
|
||||||
|
{ be_const_key(_X21_X3D, 30), be_const_func(m_nequal) },
|
||||||
{ be_const_key(clear, -1), be_const_func(m_clear) },
|
{ be_const_key(clear, -1), be_const_func(m_clear) },
|
||||||
{ be_const_key(_X21_X3D, 14), be_const_func(m_nequal) },
|
{ be_const_key(seti, 18), be_const_func(m_set) },
|
||||||
{ be_const_key(copy, 11), be_const_func(m_copy) },
|
{ be_const_key(_X2B, -1), be_const_func(m_merge) },
|
||||||
|
{ be_const_key(add, 26), be_const_func(m_add) },
|
||||||
|
{ be_const_key(deinit, -1), be_const_func(m_deinit) },
|
||||||
{ be_const_key(tostring, -1), be_const_func(m_tostring) },
|
{ be_const_key(tostring, -1), be_const_func(m_tostring) },
|
||||||
{ be_const_key(item, -1), be_const_func(m_item) },
|
{ be_const_key(item, -1), be_const_func(m_item) },
|
||||||
{ be_const_key(setbits, 29), be_const_closure(setbits_closure) },
|
{ be_const_key(geti, -1), be_const_func(m_geti) },
|
||||||
{ be_const_key(deinit, 12), be_const_func(m_deinit) },
|
{ be_const_key(resize, -1), be_const_func(m_resize) },
|
||||||
{ be_const_key(asstring, -1), be_const_func(m_asstring) },
|
|
||||||
{ be_const_key(_X2B, -1), be_const_func(m_merge) },
|
|
||||||
{ be_const_key(setitem, -1), be_const_func(m_setitem) },
|
{ be_const_key(setitem, -1), be_const_func(m_setitem) },
|
||||||
{ be_const_key(fromstring, 31), be_const_func(m_fromstring) },
|
|
||||||
{ be_const_key(_X2E_X2E, -1), be_const_func(m_connect) },
|
|
||||||
{ be_const_key(set, -1), be_const_func(m_set) },
|
|
||||||
{ be_const_key(_X3D_X3D, -1), be_const_func(m_equal) },
|
|
||||||
{ be_const_key(getbits, 18), be_const_closure(getbits_closure) },
|
|
||||||
{ be_const_key(fromhex, -1), be_const_func(m_fromhex) },
|
|
||||||
{ be_const_key(getfloat, 27), be_const_func(m_getfloat) },
|
|
||||||
{ be_const_key(init, 16), be_const_func(m_init) },
|
|
||||||
{ be_const_key(add, -1), be_const_func(m_add) },
|
|
||||||
{ be_const_key(_change_buffer, -1), be_const_func(m_change_buffer) },
|
|
||||||
{ be_const_key(_X2Elen, -1), be_const_var(1) },
|
|
||||||
{ be_const_key(get, 25), be_const_func(m_getu) },
|
|
||||||
{ be_const_key(_buffer, 22), be_const_func(m_buffer) },
|
|
||||||
{ be_const_key(fromb64, -1), be_const_func(m_fromb64) },
|
|
||||||
{ be_const_key(geti, 17), be_const_func(m_geti) },
|
|
||||||
{ be_const_key(_X2Ep, -1), be_const_var(2) },
|
{ be_const_key(_X2Ep, -1), be_const_var(2) },
|
||||||
{ be_const_key(size, -1), be_const_func(m_size) },
|
{ be_const_key(fromstring, -1), be_const_func(m_fromstring) },
|
||||||
{ be_const_key(setfloat, -1), be_const_func(m_setfloat) },
|
{ be_const_key(_X3D_X3D, -1), be_const_func(m_equal) },
|
||||||
{ be_const_key(seti, -1), be_const_func(m_set) },
|
|
||||||
{ be_const_key(tob64, -1), be_const_func(m_tob64) },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static be_define_const_map(
|
static be_define_const_map(
|
||||||
be_class_bytes_map,
|
be_class_bytes_map,
|
||||||
32
|
33
|
||||||
);
|
);
|
||||||
|
|
||||||
BE_EXPORT_VARIABLE be_define_const_class(
|
BE_EXPORT_VARIABLE be_define_const_class(
|
||||||
|
|
|
@ -715,6 +715,25 @@ static int m_tostring(bvm *vm)
|
||||||
be_return(vm);
|
be_return(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int m_tohex(bvm *vm)
|
||||||
|
{
|
||||||
|
int argc = be_top(vm);
|
||||||
|
buf_impl attr = m_read_attributes(vm, 1);
|
||||||
|
if (attr.bufptr) { /* pointer looks valid */
|
||||||
|
int32_t len = attr.len;
|
||||||
|
size_t hex_len = len * 2 + 1;
|
||||||
|
|
||||||
|
char * hex_out = be_pushbuffer(vm, hex_len);
|
||||||
|
size_t l = tohex(hex_out, hex_len, attr.bufptr, len);
|
||||||
|
|
||||||
|
be_pushnstring(vm, hex_out, l); /* make escape string from buffer */
|
||||||
|
be_remove(vm, -2); /* remove buffer */
|
||||||
|
} else { /* pointer is null, don't try to dereference it as it would crash */
|
||||||
|
be_pushstring(vm, "");
|
||||||
|
}
|
||||||
|
be_return(vm);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copy the buffer into a string without any changes
|
* Copy the buffer into a string without any changes
|
||||||
*/
|
*/
|
||||||
|
@ -1536,6 +1555,8 @@ void be_load_byteslib(bvm *vm)
|
||||||
{ "fromstring", m_fromstring },
|
{ "fromstring", m_fromstring },
|
||||||
{ "tob64", m_tob64 },
|
{ "tob64", m_tob64 },
|
||||||
{ "fromb64", m_fromb64 },
|
{ "fromb64", m_fromb64 },
|
||||||
|
{ "fromhex", m_fromhex },
|
||||||
|
{ "tohex", m_tohex },
|
||||||
{ "add", m_add },
|
{ "add", m_add },
|
||||||
{ "get", m_getu },
|
{ "get", m_getu },
|
||||||
{ "geti", m_geti },
|
{ "geti", m_geti },
|
||||||
|
@ -1578,6 +1599,7 @@ class be_class_bytes (scope: global, name: bytes) {
|
||||||
tob64, func(m_tob64)
|
tob64, func(m_tob64)
|
||||||
fromb64, func(m_fromb64)
|
fromb64, func(m_fromb64)
|
||||||
fromhex, func(m_fromhex)
|
fromhex, func(m_fromhex)
|
||||||
|
tohex, func(m_tohex)
|
||||||
add, func(m_add)
|
add, func(m_add)
|
||||||
get, func(m_getu)
|
get, func(m_getu)
|
||||||
geti, func(m_geti)
|
geti, func(m_geti)
|
||||||
|
|
Loading…
Reference in New Issue