mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-11-19 18:47:37 +01:00
sdk/hints: add lmdb implementation.
This commit is contained in:
40
sdk/hints/lmdbh/keys.go
Normal file
40
sdk/hints/lmdbh/keys.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package lmdbh
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"unsafe"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
)
|
||||
|
||||
func encodeKey(pubhintkey, relay string) []byte {
|
||||
k := make([]byte, 32+len(relay))
|
||||
hex.Decode(k[0:32], []byte(pubhintkey))
|
||||
copy(k[32:], unsafe.Slice(unsafe.StringData(relay), len(relay)))
|
||||
return k
|
||||
}
|
||||
|
||||
func parseKey(k []byte) (pubkey string, relay string) {
|
||||
pubkey = hex.EncodeToString(k[0:32])
|
||||
relay = string(k[32:])
|
||||
return
|
||||
}
|
||||
|
||||
func encodeValue(tss timestamps) []byte {
|
||||
v := make([]byte, 16)
|
||||
binary.LittleEndian.PutUint32(v[0:], uint32(tss[0]))
|
||||
binary.LittleEndian.PutUint32(v[4:], uint32(tss[1]))
|
||||
binary.LittleEndian.PutUint32(v[8:], uint32(tss[2]))
|
||||
binary.LittleEndian.PutUint32(v[12:], uint32(tss[3]))
|
||||
return v
|
||||
}
|
||||
|
||||
func parseValue(v []byte) timestamps {
|
||||
return timestamps{
|
||||
nostr.Timestamp(binary.LittleEndian.Uint32(v[0:])),
|
||||
nostr.Timestamp(binary.LittleEndian.Uint32(v[4:])),
|
||||
nostr.Timestamp(binary.LittleEndian.Uint32(v[8:])),
|
||||
nostr.Timestamp(binary.LittleEndian.Uint32(v[12:])),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user