mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
nvs_partition_generator: Add support for base64 representation of Binary data
This commit is contained in:
parent
6d0a9fe95e
commit
89b423658a
@ -19,9 +19,9 @@ Type
|
||||
Supported values are ``file``, ``data`` and ``namespace``.
|
||||
|
||||
Encoding
|
||||
Supported values are: ``u8``, ``i8``, ``u16``, ``u32``, ``i32``, ``string``, ``hex2bin`` and ``binary``. This specifies how actual data values are encoded in the resultant binary file. Difference between ``string`` and ``binary`` encoding is that ``string`` data is terminated with a NULL character, whereas ``binary`` data is not.
|
||||
Supported values are: ``u8``, ``i8``, ``u16``, ``u32``, ``i32``, ``string``, ``hex2bin``, ``base64`` and ``binary``. This specifies how actual data values are encoded in the resultant binary file. Difference between ``string`` and ``binary`` encoding is that ``string`` data is terminated with a NULL character, whereas ``binary`` data is not.
|
||||
|
||||
.. note:: For ``file`` type, only ``hex2bin``, ``string`` and ``binary`` is supported as of now.
|
||||
.. note:: For ``file`` type, only ``hex2bin``, ``base64``, ``string`` and ``binary`` is supported as of now.
|
||||
|
||||
Value
|
||||
Data value.
|
||||
|
@ -132,7 +132,7 @@ class Page(object):
|
||||
# set Type
|
||||
if encoding == "string":
|
||||
entry_struct[1] = Page.SZ
|
||||
elif encoding == "hex2bin" or encoding == "binary":
|
||||
elif encoding in ["hex2bin", "binary", "base64"]:
|
||||
entry_struct[1] = Page.BLOB
|
||||
|
||||
# compute CRC of data
|
||||
@ -248,11 +248,14 @@ class NVS(object):
|
||||
raise InputError("%s: Invalid data length. Should be multiple of 2." % key)
|
||||
value = binascii.a2b_hex(value)
|
||||
|
||||
if encoding == "base64":
|
||||
value = binascii.a2b_base64(value)
|
||||
|
||||
if encoding == "string":
|
||||
value += '\0'
|
||||
|
||||
encoding = encoding.lower()
|
||||
varlen_encodings = ["string", "binary", "hex2bin"]
|
||||
varlen_encodings = ["string", "binary", "hex2bin", "base64"]
|
||||
primitive_encodings = ["u8", "i8", "u16", "u32", "i32"]
|
||||
if encoding in varlen_encodings:
|
||||
try:
|
||||
@ -308,7 +311,7 @@ def write_entry(nvs_instance, key, datatype, encoding, value):
|
||||
:param nvs_instance: Instance of an NVS class returned by nvs_open()
|
||||
:param key: Key of the data
|
||||
:param datatype: Data type. Valid values are "file", "data" and "namespace"
|
||||
:param encoding: Data encoding. Valid values are "u8", "i8", "u16", "u32", "i32", "string", "binary" and "hex2bin"
|
||||
:param encoding: Data encoding. Valid values are "u8", "i8", "u16", "u32", "i32", "string", "binary", "hex2bin" and "base64"
|
||||
:param value: Data value in ascii encoded string format for "data" datatype and filepath for "file" datatype
|
||||
:return: None
|
||||
"""
|
||||
|
@ -7,6 +7,8 @@ dummyU32Key,data,u32,4294967295
|
||||
dummyI32Key,data,i32,-2147483648
|
||||
dummyStringKey,data,string,0A:0B:0C:0D:0E:0F
|
||||
dummyHex2BinKey,data,hex2bin,010203abcdef
|
||||
dummyBase64Key,data,base64,MTIzYWJj
|
||||
hexFileKey,file,hex2bin,testdata/sample.hex
|
||||
base64FileKey,file,base64,testdata/sample.base64
|
||||
stringFileKey,file,string,testdata/sample.txt
|
||||
binFileKey,file,binary,testdata/sample.bin
|
||||
|
|
1
components/nvs_flash/nvs_partition_generator/testdata/sample.base64
vendored
Normal file
1
components/nvs_flash/nvs_partition_generator/testdata/sample.base64
vendored
Normal file
@ -0,0 +1 @@
|
||||
AQIDBAUGBwgJq83v
|
@ -1548,6 +1548,9 @@ TEST_CASE("read data from partition generated via partition generation utility",
|
||||
uint8_t hexdata[] = {0x01, 0x02, 0x03, 0xab, 0xcd, 0xef};
|
||||
TEST_ESP_OK( nvs_get_blob(handle, "dummyHex2BinKey", buf, &buflen));
|
||||
CHECK(memcmp(buf, hexdata, buflen) == 0);
|
||||
uint8_t base64data[] = {'1', '2', '3', 'a', 'b', 'c'};
|
||||
TEST_ESP_OK( nvs_get_blob(handle, "dummyBase64Key", buf, &buflen));
|
||||
CHECK(memcmp(buf, base64data, buflen) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("dump all performance data", "[nvs]")
|
||||
|
Loading…
x
Reference in New Issue
Block a user