nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

print_util.h (1242B)


      1 #include "hex.h"
      2 #include "lmdb.h"
      3 
      4 static void ndb_print_text_search_key(struct ndb_text_search_key *key)
      5 {
      6 	fprintf(stderr,"K<'%.*s' %" PRIu64 " %" PRIu64 " note_id:%" PRIu64 ">", key->str_len, key->str,
      7 						    key->word_index,
      8 						    key->timestamp,
      9 						    key->note_id);
     10 }
     11 
     12 static void print_hex(unsigned char* data, size_t size) {
     13 	size_t i;
     14 	for (i = 0; i < size; i++) {
     15 		printf("%02x", data[i]);
     16 	}
     17 }
     18 
     19 static void print_tag_kv(struct ndb_txn *txn, MDB_val *k, MDB_val *v)
     20 {
     21 	char hex_id[65];
     22 	struct ndb_note *note;
     23 	uint64_t ts;
     24 
     25 	ts = *(uint64_t*)(k->mv_data+(k->mv_size-8));
     26 
     27 	// TODO: p tags, etc
     28 	if (((const char*)k->mv_data)[0] == 'e' && k->mv_size == (1 + 32 + 8)) {
     29 		printf("note_tags 'e");
     30 		print_hex(k->mv_data+1, 32);
     31 		printf("' %" PRIu64, ts);
     32 	} else {
     33 		printf("note_tags '%.*s' %" PRIu64, (int)k->mv_size-8,
     34 		       (const char *)k->mv_data, ts);
     35 	}
     36 
     37 	ts = *(uint64_t*)v->mv_data;
     38 
     39 	note = ndb_get_note_by_key(txn, ts, NULL);
     40 	assert(note);
     41 	hex_encode(ndb_note_id(note), 32, hex_id);
     42 	printf(" note_key:%" PRIu64 " id:%s\n", ts, hex_id);
     43 }
     44 
     45 static void print_hex_stream(FILE *stream, unsigned char* data, size_t size) {
     46 	size_t i;
     47 	for (i = 0; i < size; i++) {
     48 		fprintf(stream, "%02x", data[i]);
     49 	}
     50 }
     51 
     52