don't expose storage in blocks
This commit is contained in:
parent
4169663a8b
commit
5e23bc96ca
13
libs/microbit/shims.d.ts
vendored
13
libs/microbit/shims.d.ts
vendored
@ -587,33 +587,34 @@ declare interface Buffer {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to save and read values in the flash storage
|
* This allows reading and writing of small blocks of data to FLASH memory.
|
||||||
*/
|
*/
|
||||||
//% weight=10 color=#cc6600
|
//% weight=10 color=#cc6600
|
||||||
declare namespace storage {
|
declare namespace storage {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the key and buffer pair into flash.
|
* Writes the key and buffer pair into FLASH. This operation is rather costly as all the key/value pairs
|
||||||
|
* have to be rewritten as well.
|
||||||
*/
|
*/
|
||||||
//% blockId="storage_put_buffer" block="storage put buffer %key|with %buffer" weight=50 shim=storage::putBuffer
|
//% shim=storage::putBuffer
|
||||||
function putBuffer(key: string, buffer: Buffer): void;
|
function putBuffer(key: string, buffer: Buffer): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the buffer at the given key if any. If no key is available, empty buffer is returned.
|
* Gets the buffer at the given key if any. If no key is available, empty buffer is returned.
|
||||||
*/
|
*/
|
||||||
//% blockId="storage_get_buffer" block="storage get buffer %key" weight=49 shim=storage::getBuffer
|
//% shim=storage::getBuffer
|
||||||
function getBuffer(key: string): Buffer;
|
function getBuffer(key: string): Buffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes an entry identified by the key.
|
* Removes an entry identified by the key.
|
||||||
*/
|
*/
|
||||||
//% blockId="storage_remove" block="storage remove %key" weight=20 shim=storage::remove
|
//% shim=storage::remove
|
||||||
function remove(key: string): void;
|
function remove(key: string): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of entries in the key value store
|
* The number of entries in the key value store
|
||||||
*/
|
*/
|
||||||
//% blockId="storage_size" block="storage size" weight=10 shim=storage::size
|
//% shim=storage::size
|
||||||
function size(): number;
|
function size(): number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
#include "ksbit.h"
|
#include "ksbit.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to save and read values in the flash storage
|
* This allows reading and writing of small blocks of data to FLASH memory.
|
||||||
*/
|
*/
|
||||||
//% weight=10 color=#cc6600
|
//% weight=10 color=#cc6600
|
||||||
namespace storage {
|
namespace storage {
|
||||||
/**
|
/**
|
||||||
* Writes the key and buffer pair into flash.
|
* Writes the key and buffer pair into FLASH. This operation is rather costly as all the key/value pairs
|
||||||
|
* have to be rewritten as well.
|
||||||
*/
|
*/
|
||||||
//% blockId="storage_put_buffer" block="storage put buffer %key|with %buffer" weight=50
|
//%
|
||||||
void putBuffer(StringData* key, Buffer buffer) {
|
void putBuffer(StringData* key, Buffer buffer) {
|
||||||
uBit.storage.put(ManagedString(key), ManagedBuffer(buffer).getBytes());
|
uBit.storage.put(ManagedString(key), ManagedBuffer(buffer).getBytes());
|
||||||
}
|
}
|
||||||
@ -16,7 +17,7 @@ namespace storage {
|
|||||||
/**
|
/**
|
||||||
* Gets the buffer at the given key if any. If no key is available, empty buffer is returned.
|
* Gets the buffer at the given key if any. If no key is available, empty buffer is returned.
|
||||||
*/
|
*/
|
||||||
//% blockId="storage_get_buffer" block="storage get buffer %key" weight=49
|
//%
|
||||||
Buffer getBuffer(StringData* key) {
|
Buffer getBuffer(StringData* key) {
|
||||||
KeyValuePair* pv = uBit.storage.get(ManagedString(key));
|
KeyValuePair* pv = uBit.storage.get(ManagedString(key));
|
||||||
if (pv == NULL) return ManagedBuffer().leakData();
|
if (pv == NULL) return ManagedBuffer().leakData();
|
||||||
@ -27,7 +28,7 @@ namespace storage {
|
|||||||
/**
|
/**
|
||||||
* Removes an entry identified by the key.
|
* Removes an entry identified by the key.
|
||||||
*/
|
*/
|
||||||
//% blockId="storage_remove" block="storage remove %key" weight=20
|
//%
|
||||||
void remove(StringData * key) {
|
void remove(StringData * key) {
|
||||||
uBit.storage.remove(ManagedString(key));
|
uBit.storage.remove(ManagedString(key));
|
||||||
}
|
}
|
||||||
@ -35,7 +36,7 @@ namespace storage {
|
|||||||
/**
|
/**
|
||||||
* The number of entries in the key value store
|
* The number of entries in the key value store
|
||||||
*/
|
*/
|
||||||
//% blockId="storage_size" block="storage size" weight=10
|
//%
|
||||||
int size() {
|
int size() {
|
||||||
return uBit.storage.size();
|
return uBit.storage.size();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user