esp8266ndn
NDN Arduino library for ESP8266 and more
Loading...
Searching...
No Matches
packet.hpp
Go to the documentation of this file.
1#ifndef NDNPH_STORE_PACKET_HPP
2#define NDNPH_STORE_PACKET_HPP
3
4#include "kv.hpp"
5
6namespace ndnph {
7
12template<typename T>
13class PacketStore : public KvStore {
14public:
15 using KvStore::KvStore;
16
23 T get(const char* key, Region& region) {
24 tlv::Value wire = KvStore::get(key, region);
25 if (wire.size() == 0) {
26 return T();
27 }
28
29 T packet = region.create<T>();
30 if (!packet || !wire.makeDecoder().decode(packet)) {
31 return T();
32 }
33 return packet;
34 }
35
43 template<typename Encodable>
44 bool set(const char* key, Encodable value, Region& region) {
45 ScopedEncoder encoder(region);
46 if (!encoder.prepend(value)) {
47 return false;
48 }
49 return KvStore::set(key, tlv::Value(encoder));
50 }
51};
52
53} // namespace ndnph
54
55#endif // NDNPH_STORE_PACKET_HPP
bool decode(T &target) const
Decode first TLV into target object.
Definition decoder.hpp:158
bool prepend(const First &first, const Arg &... arg)
Prepend a sequence of values.
Definition encoder.hpp:123
File based key-value store.
Definition kv.hpp:10
tlv::Value get(const char *key, Region &region)
Retrieve a value.
Definition kv.hpp:38
bool set(const char *key, tlv::Value value)
Store a value.
Definition kv.hpp:69
KvStore()=default
Constructor to use internal FileStore instance.
File based packet store.
Definition packet.hpp:13
T get(const char *key, Region &region)
Retrieve a packet.
Definition packet.hpp:23
bool set(const char *key, Encodable value, Region &region)
Store a packet.
Definition packet.hpp:44
Region-based memory allocator thats owns memory of NDNph objects.
Definition region.hpp:9
RefType create(Arg &&... arg)
Allocate and create an object, and return its reference.
Definition region.hpp:90
Encoder that auto-discards upon destruction.
Definition encoder.hpp:198
A sequence of bytes, usually TLV-VALUE.
Definition value.hpp:11
Decoder makeDecoder() const
Create a Decoder over this value buffer.
Definition value.hpp:64
size_t size() const
Definition value.hpp:46
Definition fs.hpp:33