metadata.h (1826B)
1 #ifndef NDB_METADATA_H 2 #define NDB_METADATA_H 3 4 #include "nostrdb.h" 5 6 enum ndb_meta_clone_result { 7 NDB_META_CLONE_FAILED, 8 NDB_META_CLONE_EXISTING_ENTRY, 9 NDB_META_CLONE_NEW_ENTRY, 10 }; 11 12 enum ndb_meta_clone_result ndb_note_meta_clone_with_entry( 13 struct ndb_note_meta **meta, 14 struct ndb_note_meta_entry **entry, 15 uint16_t type, 16 uint64_t *payload, 17 unsigned char *buf, 18 size_t bufsize); 19 20 // these must be byte-aligned, they are directly accessing the serialized data 21 // representation 22 #pragma pack(push, 1) 23 24 // 16 bytes 25 struct ndb_note_meta_entry { 26 // 4 byte entry header 27 uint16_t type; 28 29 union { 30 uint16_t flags; 31 uint16_t reposts; 32 } aux2; 33 34 // additional 4 bytes of aux storage for payloads that are >8 bytes 35 // 36 // for reactions types, this is used for counts 37 // normally this would have been padding but we make use of it 38 // in our manually packed structure 39 union { 40 uint32_t value; 41 42 /* if this is a thread root, this counts the total replies in the thread */ 43 uint32_t total_reactions; 44 } aux; 45 46 // 8 byte metadata payload 47 union { 48 uint64_t value; 49 50 struct { 51 uint32_t offset; 52 uint32_t padding; 53 } offset; 54 55 struct { 56 /* number of direct replies */ 57 uint16_t direct_replies; 58 uint16_t quotes; 59 60 /* number of replies in this thread */ 61 uint32_t thread_replies; 62 } counts; 63 64 // the reaction binmoji[1] for reaction, count is stored in aux 65 union ndb_reaction_str reaction_str; 66 } payload; 67 }; 68 STATIC_ASSERT(sizeof(struct ndb_note_meta_entry) == 16, note_meta_entry_should_be_16_bytes); 69 70 struct ndb_note_meta { 71 // 4 bytes 72 uint8_t version; 73 uint8_t padding; 74 uint16_t count; 75 76 // 4 bytes 77 uint32_t data_table_size; 78 79 // 8 bytes 80 uint64_t flags; 81 }; 82 STATIC_ASSERT(sizeof(struct ndb_note_meta) == 16, note_meta_entry_should_be_16_bytes); 83 84 #pragma pack(pop) 85 86 #endif /* NDB_METADATA_H */