return mod->table_key_printf(id, buf, buflen, leaf);
}
+int bpf_table_key_sscanf(void *program, size_t id, const char *buf, void *key) {
+ auto mod = static_cast<ebpf::BPFModule *>(program);
+ if (!mod) return 0;
+ return mod->table_key_scanf(id, buf, key);
+}
+int bpf_table_leaf_sscanf(void *program, size_t id, const char *buf, void *leaf) {
+ auto mod = static_cast<ebpf::BPFModule *>(program);
+ if (!mod) return 0;
+ return mod->table_key_scanf(id, buf, leaf);
+}
+
}
size_t bpf_table_leaf_size_id(void *program, size_t id);
int bpf_table_key_snprintf(void *program, size_t id, char *buf, size_t buflen, const void *key);
int bpf_table_leaf_snprintf(void *program, size_t id, char *buf, size_t buflen, const void *leaf);
-//int bpf_table_key_sscanf(void *program, size_t id, const char *buf, void *key);
-//int bpf_table_leaf_sscanf(void *program, size_t id, const char *buf, void *leaf);
+int bpf_table_key_sscanf(void *program, size_t id, const char *buf, void *key);
+int bpf_table_leaf_sscanf(void *program, size_t id, const char *buf, void *leaf);
int bpf_table_update(void *program, const char *table_name, const char *key, const char *leaf);
int bpf_table_update_id(void *program, size_t id, const char *key, const char *leaf);
return 0;
}
+int BPFModule::table_key_scanf(size_t id, const char *key_str, void *key) {
+ if (id >= tables_->size()) return -1;
+
+ const TableDesc &desc = (*tables_)[id];
+ if (desc.fd < 0) return -1;
+
+ if (!rw_engine_ || !desc.key_reader) {
+ fprintf(stderr, "Table sscanf not available\n");
+ return -1;
+ }
+
+ vector<GenericValue> args({GenericValue(), GenericValue((void *)key_str), GenericValue(key)});
+ GenericValue rc = rw_engine_->runFunction(desc.key_reader, args);
+ if (rc.IntVal != 0)
+ return -1;
+ return 0;
+}
+
+int BPFModule::table_leaf_scanf(size_t id, const char *leaf_str, void *leaf) {
+ if (id >= tables_->size()) return -1;
+
+ const TableDesc &desc = (*tables_)[id];
+ if (desc.fd < 0) return -1;
+
+ if (!rw_engine_ || !desc.leaf_reader) {
+ fprintf(stderr, "Table sscanf not available\n");
+ return -1;
+ }
+
+ vector<GenericValue> args({GenericValue(), GenericValue((void *)leaf_str), GenericValue(leaf)});
+ GenericValue rc = rw_engine_->runFunction(desc.leaf_reader, args);
+ if (rc.IntVal != 0)
+ return -1;
+ return 0;
+}
+
// load a B file, which comes in two parts
int BPFModule::load_b(const string &filename, const string &proto_filename) {
if (!sections_.empty()) {
size_t table_key_size(size_t id) const;
size_t table_key_size(const std::string &name) const;
int table_key_printf(size_t id, char *buf, size_t buflen, const void *key);
+ int table_key_scanf(size_t id, const char *buf, void *key);
const char * table_leaf_desc(size_t id) const;
const char * table_leaf_desc(const std::string &name) const;
size_t table_leaf_size(size_t id) const;
size_t table_leaf_size(const std::string &name) const;
int table_leaf_printf(size_t id, char *buf, size_t buflen, const void *leaf);
+ int table_leaf_scanf(size_t id, const char *buf, void *leaf);
int table_update(size_t id, const char *key, const char *leaf);
int table_update(const std::string &name, const char *key, const char *leaf);
char * license() const;