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 (1360B)


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