2022-11-15 16:29:37 -03:00
|
|
|
package nip19
|
|
|
|
|
|
|
|
import (
|
2022-12-27 07:49:26 -03:00
|
|
|
"bytes"
|
2022-11-15 16:29:37 -03:00
|
|
|
)
|
|
|
|
|
2022-12-27 07:49:26 -03:00
|
|
|
const (
|
|
|
|
TLVDefault uint8 = 0
|
|
|
|
TLVRelay uint8 = 1
|
2023-02-27 16:15:04 -03:00
|
|
|
TLVAuthor uint8 = 2
|
|
|
|
TLVKind uint8 = 3
|
2022-12-27 07:49:26 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
func readTLVEntry(data []byte) (typ uint8, value []byte) {
|
|
|
|
if len(data) < 2 {
|
|
|
|
return 0, nil
|
2022-11-15 16:29:37 -03:00
|
|
|
}
|
|
|
|
|
2022-12-27 07:49:26 -03:00
|
|
|
typ = data[0]
|
|
|
|
length := int(data[1])
|
|
|
|
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)
|
2022-11-15 16:29:37 -03:00
|
|
|
}
|