mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 13:22:56 +01:00
35 lines
518 B
Go
35 lines
518 B
Go
package nip19
|
|
|
|
import (
|
|
"bytes"
|
|
)
|
|
|
|
const (
|
|
TLVDefault uint8 = 0
|
|
TLVRelay uint8 = 1
|
|
TLVAuthor uint8 = 2
|
|
TLVKind uint8 = 3
|
|
)
|
|
|
|
func readTLVEntry(data []byte) (typ uint8, value []byte) {
|
|
if len(data) < 2 {
|
|
return 0, nil
|
|
}
|
|
|
|
typ = data[0]
|
|
length := int(data[1])
|
|
if len(data) < 2+length {
|
|
return typ, nil
|
|
}
|
|
|
|
value = data[2 : 2+length]
|
|
return
|
|
}
|
|
|
|
func writeTLVEntry(buf *bytes.Buffer, typ uint8, value []byte) {
|
|
length := len(value)
|
|
buf.WriteByte(typ)
|
|
buf.WriteByte(uint8(length))
|
|
buf.Write(value)
|
|
}
|