create new tag constructors for more flexibility
This commit is contained in:
@@ -302,7 +302,7 @@ func (f *F) Unmarshal(b []byte) (r []byte, err error) {
|
||||
return
|
||||
}
|
||||
ff = append([][]byte{k}, ff...)
|
||||
s := append(*f.Tags, tag.New(ff...))
|
||||
s := append(*f.Tags, tag.NewFromByteSlice(ff...))
|
||||
f.Tags = &s
|
||||
// f.Tags.F = append(f.Tags.F, tag.New(ff...))
|
||||
// }
|
||||
@@ -317,7 +317,7 @@ func (f *F) Unmarshal(b []byte) (r []byte, err error) {
|
||||
); chk.E(err) {
|
||||
return
|
||||
}
|
||||
f.Ids = tag.New(ff...)
|
||||
f.Ids = tag.NewFromByteSlice(ff...)
|
||||
state = betweenKV
|
||||
case Kinds[0]:
|
||||
if len(key) < len(Kinds) {
|
||||
@@ -338,7 +338,7 @@ func (f *F) Unmarshal(b []byte) (r []byte, err error) {
|
||||
); chk.E(err) {
|
||||
return
|
||||
}
|
||||
f.Authors = tag.New(ff...)
|
||||
f.Authors = tag.NewFromByteSlice(ff...)
|
||||
state = betweenKV
|
||||
case Until[0]:
|
||||
if len(key) < len(Until) {
|
||||
|
||||
@@ -88,7 +88,7 @@ func GenFilter() (f *F, err error) {
|
||||
idb = append(idb, id)
|
||||
}
|
||||
idb = append([][]byte{{'#', byte(b)}}, idb...)
|
||||
*f.Tags = append(*f.Tags, tag.New(idb...))
|
||||
*f.Tags = append(*f.Tags, tag.NewFromByteSlice(idb...))
|
||||
// f.Tags.F = append(f.Tags.F, tag.FromBytesSlice(idb...))
|
||||
}
|
||||
tn := int(timestamp.Now().I64())
|
||||
|
||||
@@ -23,18 +23,26 @@ type T struct {
|
||||
b bufpool.B
|
||||
}
|
||||
|
||||
func New(t ...any) *T {
|
||||
var bs [][]byte
|
||||
func New() *T { return &T{b: bufpool.Get()} }
|
||||
|
||||
func NewFromByteSlice(t ...[]byte) (tt *T) {
|
||||
tt = &T{T: t, b: bufpool.Get()}
|
||||
return
|
||||
}
|
||||
|
||||
func NewFromAny(t ...any) (tt *T) {
|
||||
tt = &T{b: bufpool.Get()}
|
||||
for _, v := range t {
|
||||
if vb, ok := v.([]byte); ok {
|
||||
bs = append(bs, vb)
|
||||
} else if vs, ok := v.(string); ok {
|
||||
bs = append(bs, []byte(vs))
|
||||
} else {
|
||||
panic("programmer error: type of tag element is not []byte or string")
|
||||
switch vv := v.(type) {
|
||||
case []byte:
|
||||
tt.T = append(tt.T, vv)
|
||||
case string:
|
||||
tt.T = append(tt.T, []byte(vv))
|
||||
default:
|
||||
panic("invalid type for tag fields, must be []byte or string")
|
||||
}
|
||||
}
|
||||
return &T{T: bs, b: bufpool.Get()}
|
||||
return
|
||||
}
|
||||
|
||||
func NewWithCap(c int) *T {
|
||||
|
||||
Reference in New Issue
Block a user