mirror of
https://github.com/asticode/go-astiav.git
synced 2025-09-26 20:21:15 +08:00
Moved bit flags to astikit
This commit is contained in:
9
flag.go
9
flag.go
@@ -1,9 +0,0 @@
|
||||
package astiav
|
||||
|
||||
type flags int
|
||||
|
||||
func (fs flags) add(f int) int { return int(fs) | f }
|
||||
|
||||
func (fs flags) del(f int) int { return int(fs) &^ f }
|
||||
|
||||
func (fs flags) has(f int) bool { return int(fs)&f > 0 }
|
17
flag_test.go
17
flag_test.go
@@ -1,17 +0,0 @@
|
||||
package astiav
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestFlag(t *testing.T) {
|
||||
f := flags(2 | 4)
|
||||
r := f.add(1)
|
||||
require.Equal(t, 7, r)
|
||||
r = f.del(2)
|
||||
require.Equal(t, 4, r)
|
||||
require.False(t, f.has(1))
|
||||
require.True(t, f.has(4))
|
||||
}
|
116
flags.go
116
flags.go
@@ -1,7 +1,11 @@
|
||||
// Code generated by astiav. DO NOT EDIT.
|
||||
package astiav
|
||||
|
||||
type BuffersinkFlags flags
|
||||
import (
|
||||
"github.com/asticode/go-astikit"
|
||||
)
|
||||
|
||||
type BuffersinkFlags astikit.BitFlags
|
||||
|
||||
func NewBuffersinkFlags(fs ...BuffersinkFlag) BuffersinkFlags {
|
||||
o := BuffersinkFlags(0)
|
||||
@@ -12,16 +16,16 @@ func NewBuffersinkFlags(fs ...BuffersinkFlag) BuffersinkFlags {
|
||||
}
|
||||
|
||||
func (fs BuffersinkFlags) Add(f BuffersinkFlag) BuffersinkFlags {
|
||||
return BuffersinkFlags(flags(fs).add(int(f)))
|
||||
return BuffersinkFlags(astikit.BitFlags(fs).Add(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs BuffersinkFlags) Del(f BuffersinkFlag) BuffersinkFlags {
|
||||
return BuffersinkFlags(flags(fs).del(int(f)))
|
||||
return BuffersinkFlags(astikit.BitFlags(fs).Del(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs BuffersinkFlags) Has(f BuffersinkFlag) bool { return flags(fs).has(int(f)) }
|
||||
func (fs BuffersinkFlags) Has(f BuffersinkFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||
|
||||
type BuffersrcFlags flags
|
||||
type BuffersrcFlags astikit.BitFlags
|
||||
|
||||
func NewBuffersrcFlags(fs ...BuffersrcFlag) BuffersrcFlags {
|
||||
o := BuffersrcFlags(0)
|
||||
@@ -32,16 +36,16 @@ func NewBuffersrcFlags(fs ...BuffersrcFlag) BuffersrcFlags {
|
||||
}
|
||||
|
||||
func (fs BuffersrcFlags) Add(f BuffersrcFlag) BuffersrcFlags {
|
||||
return BuffersrcFlags(flags(fs).add(int(f)))
|
||||
return BuffersrcFlags(astikit.BitFlags(fs).Add(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs BuffersrcFlags) Del(f BuffersrcFlag) BuffersrcFlags {
|
||||
return BuffersrcFlags(flags(fs).del(int(f)))
|
||||
return BuffersrcFlags(astikit.BitFlags(fs).Del(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs BuffersrcFlags) Has(f BuffersrcFlag) bool { return flags(fs).has(int(f)) }
|
||||
func (fs BuffersrcFlags) Has(f BuffersrcFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||
|
||||
type CodecContextFlags flags
|
||||
type CodecContextFlags astikit.BitFlags
|
||||
|
||||
func NewCodecContextFlags(fs ...CodecContextFlag) CodecContextFlags {
|
||||
o := CodecContextFlags(0)
|
||||
@@ -52,16 +56,16 @@ func NewCodecContextFlags(fs ...CodecContextFlag) CodecContextFlags {
|
||||
}
|
||||
|
||||
func (fs CodecContextFlags) Add(f CodecContextFlag) CodecContextFlags {
|
||||
return CodecContextFlags(flags(fs).add(int(f)))
|
||||
return CodecContextFlags(astikit.BitFlags(fs).Add(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs CodecContextFlags) Del(f CodecContextFlag) CodecContextFlags {
|
||||
return CodecContextFlags(flags(fs).del(int(f)))
|
||||
return CodecContextFlags(astikit.BitFlags(fs).Del(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs CodecContextFlags) Has(f CodecContextFlag) bool { return flags(fs).has(int(f)) }
|
||||
func (fs CodecContextFlags) Has(f CodecContextFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||
|
||||
type CodecContextFlags2 flags
|
||||
type CodecContextFlags2 astikit.BitFlags
|
||||
|
||||
func NewCodecContextFlags2(fs ...CodecContextFlag2) CodecContextFlags2 {
|
||||
o := CodecContextFlags2(0)
|
||||
@@ -72,16 +76,16 @@ func NewCodecContextFlags2(fs ...CodecContextFlag2) CodecContextFlags2 {
|
||||
}
|
||||
|
||||
func (fs CodecContextFlags2) Add(f CodecContextFlag2) CodecContextFlags2 {
|
||||
return CodecContextFlags2(flags(fs).add(int(f)))
|
||||
return CodecContextFlags2(astikit.BitFlags(fs).Add(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs CodecContextFlags2) Del(f CodecContextFlag2) CodecContextFlags2 {
|
||||
return CodecContextFlags2(flags(fs).del(int(f)))
|
||||
return CodecContextFlags2(astikit.BitFlags(fs).Del(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs CodecContextFlags2) Has(f CodecContextFlag2) bool { return flags(fs).has(int(f)) }
|
||||
func (fs CodecContextFlags2) Has(f CodecContextFlag2) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||
|
||||
type DictionaryFlags flags
|
||||
type DictionaryFlags astikit.BitFlags
|
||||
|
||||
func NewDictionaryFlags(fs ...DictionaryFlag) DictionaryFlags {
|
||||
o := DictionaryFlags(0)
|
||||
@@ -92,16 +96,16 @@ func NewDictionaryFlags(fs ...DictionaryFlag) DictionaryFlags {
|
||||
}
|
||||
|
||||
func (fs DictionaryFlags) Add(f DictionaryFlag) DictionaryFlags {
|
||||
return DictionaryFlags(flags(fs).add(int(f)))
|
||||
return DictionaryFlags(astikit.BitFlags(fs).Add(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs DictionaryFlags) Del(f DictionaryFlag) DictionaryFlags {
|
||||
return DictionaryFlags(flags(fs).del(int(f)))
|
||||
return DictionaryFlags(astikit.BitFlags(fs).Del(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs DictionaryFlags) Has(f DictionaryFlag) bool { return flags(fs).has(int(f)) }
|
||||
func (fs DictionaryFlags) Has(f DictionaryFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||
|
||||
type FilterCommandFlags flags
|
||||
type FilterCommandFlags astikit.BitFlags
|
||||
|
||||
func NewFilterCommandFlags(fs ...FilterCommandFlag) FilterCommandFlags {
|
||||
o := FilterCommandFlags(0)
|
||||
@@ -112,16 +116,16 @@ func NewFilterCommandFlags(fs ...FilterCommandFlag) FilterCommandFlags {
|
||||
}
|
||||
|
||||
func (fs FilterCommandFlags) Add(f FilterCommandFlag) FilterCommandFlags {
|
||||
return FilterCommandFlags(flags(fs).add(int(f)))
|
||||
return FilterCommandFlags(astikit.BitFlags(fs).Add(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs FilterCommandFlags) Del(f FilterCommandFlag) FilterCommandFlags {
|
||||
return FilterCommandFlags(flags(fs).del(int(f)))
|
||||
return FilterCommandFlags(astikit.BitFlags(fs).Del(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs FilterCommandFlags) Has(f FilterCommandFlag) bool { return flags(fs).has(int(f)) }
|
||||
func (fs FilterCommandFlags) Has(f FilterCommandFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||
|
||||
type FormatContextCtxFlags flags
|
||||
type FormatContextCtxFlags astikit.BitFlags
|
||||
|
||||
func NewFormatContextCtxFlags(fs ...FormatContextCtxFlag) FormatContextCtxFlags {
|
||||
o := FormatContextCtxFlags(0)
|
||||
@@ -132,16 +136,16 @@ func NewFormatContextCtxFlags(fs ...FormatContextCtxFlag) FormatContextCtxFlags
|
||||
}
|
||||
|
||||
func (fs FormatContextCtxFlags) Add(f FormatContextCtxFlag) FormatContextCtxFlags {
|
||||
return FormatContextCtxFlags(flags(fs).add(int(f)))
|
||||
return FormatContextCtxFlags(astikit.BitFlags(fs).Add(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs FormatContextCtxFlags) Del(f FormatContextCtxFlag) FormatContextCtxFlags {
|
||||
return FormatContextCtxFlags(flags(fs).del(int(f)))
|
||||
return FormatContextCtxFlags(astikit.BitFlags(fs).Del(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs FormatContextCtxFlags) Has(f FormatContextCtxFlag) bool { return flags(fs).has(int(f)) }
|
||||
func (fs FormatContextCtxFlags) Has(f FormatContextCtxFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||
|
||||
type FormatContextFlags flags
|
||||
type FormatContextFlags astikit.BitFlags
|
||||
|
||||
func NewFormatContextFlags(fs ...FormatContextFlag) FormatContextFlags {
|
||||
o := FormatContextFlags(0)
|
||||
@@ -152,16 +156,16 @@ func NewFormatContextFlags(fs ...FormatContextFlag) FormatContextFlags {
|
||||
}
|
||||
|
||||
func (fs FormatContextFlags) Add(f FormatContextFlag) FormatContextFlags {
|
||||
return FormatContextFlags(flags(fs).add(int(f)))
|
||||
return FormatContextFlags(astikit.BitFlags(fs).Add(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs FormatContextFlags) Del(f FormatContextFlag) FormatContextFlags {
|
||||
return FormatContextFlags(flags(fs).del(int(f)))
|
||||
return FormatContextFlags(astikit.BitFlags(fs).Del(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs FormatContextFlags) Has(f FormatContextFlag) bool { return flags(fs).has(int(f)) }
|
||||
func (fs FormatContextFlags) Has(f FormatContextFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||
|
||||
type FormatEventFlags flags
|
||||
type FormatEventFlags astikit.BitFlags
|
||||
|
||||
func NewFormatEventFlags(fs ...FormatEventFlag) FormatEventFlags {
|
||||
o := FormatEventFlags(0)
|
||||
@@ -172,16 +176,16 @@ func NewFormatEventFlags(fs ...FormatEventFlag) FormatEventFlags {
|
||||
}
|
||||
|
||||
func (fs FormatEventFlags) Add(f FormatEventFlag) FormatEventFlags {
|
||||
return FormatEventFlags(flags(fs).add(int(f)))
|
||||
return FormatEventFlags(astikit.BitFlags(fs).Add(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs FormatEventFlags) Del(f FormatEventFlag) FormatEventFlags {
|
||||
return FormatEventFlags(flags(fs).del(int(f)))
|
||||
return FormatEventFlags(astikit.BitFlags(fs).Del(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs FormatEventFlags) Has(f FormatEventFlag) bool { return flags(fs).has(int(f)) }
|
||||
func (fs FormatEventFlags) Has(f FormatEventFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||
|
||||
type IOContextFlags flags
|
||||
type IOContextFlags astikit.BitFlags
|
||||
|
||||
func NewIOContextFlags(fs ...IOContextFlag) IOContextFlags {
|
||||
o := IOContextFlags(0)
|
||||
@@ -192,16 +196,16 @@ func NewIOContextFlags(fs ...IOContextFlag) IOContextFlags {
|
||||
}
|
||||
|
||||
func (fs IOContextFlags) Add(f IOContextFlag) IOContextFlags {
|
||||
return IOContextFlags(flags(fs).add(int(f)))
|
||||
return IOContextFlags(astikit.BitFlags(fs).Add(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs IOContextFlags) Del(f IOContextFlag) IOContextFlags {
|
||||
return IOContextFlags(flags(fs).del(int(f)))
|
||||
return IOContextFlags(astikit.BitFlags(fs).Del(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs IOContextFlags) Has(f IOContextFlag) bool { return flags(fs).has(int(f)) }
|
||||
func (fs IOContextFlags) Has(f IOContextFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||
|
||||
type IOFormatFlags flags
|
||||
type IOFormatFlags astikit.BitFlags
|
||||
|
||||
func NewIOFormatFlags(fs ...IOFormatFlag) IOFormatFlags {
|
||||
o := IOFormatFlags(0)
|
||||
@@ -212,16 +216,16 @@ func NewIOFormatFlags(fs ...IOFormatFlag) IOFormatFlags {
|
||||
}
|
||||
|
||||
func (fs IOFormatFlags) Add(f IOFormatFlag) IOFormatFlags {
|
||||
return IOFormatFlags(flags(fs).add(int(f)))
|
||||
return IOFormatFlags(astikit.BitFlags(fs).Add(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs IOFormatFlags) Del(f IOFormatFlag) IOFormatFlags {
|
||||
return IOFormatFlags(flags(fs).del(int(f)))
|
||||
return IOFormatFlags(astikit.BitFlags(fs).Del(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs IOFormatFlags) Has(f IOFormatFlag) bool { return flags(fs).has(int(f)) }
|
||||
func (fs IOFormatFlags) Has(f IOFormatFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||
|
||||
type PacketFlags flags
|
||||
type PacketFlags astikit.BitFlags
|
||||
|
||||
func NewPacketFlags(fs ...PacketFlag) PacketFlags {
|
||||
o := PacketFlags(0)
|
||||
@@ -232,16 +236,16 @@ func NewPacketFlags(fs ...PacketFlag) PacketFlags {
|
||||
}
|
||||
|
||||
func (fs PacketFlags) Add(f PacketFlag) PacketFlags {
|
||||
return PacketFlags(flags(fs).add(int(f)))
|
||||
return PacketFlags(astikit.BitFlags(fs).Add(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs PacketFlags) Del(f PacketFlag) PacketFlags {
|
||||
return PacketFlags(flags(fs).del(int(f)))
|
||||
return PacketFlags(astikit.BitFlags(fs).Del(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs PacketFlags) Has(f PacketFlag) bool { return flags(fs).has(int(f)) }
|
||||
func (fs PacketFlags) Has(f PacketFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||
|
||||
type SeekFlags flags
|
||||
type SeekFlags astikit.BitFlags
|
||||
|
||||
func NewSeekFlags(fs ...SeekFlag) SeekFlags {
|
||||
o := SeekFlags(0)
|
||||
@@ -252,16 +256,16 @@ func NewSeekFlags(fs ...SeekFlag) SeekFlags {
|
||||
}
|
||||
|
||||
func (fs SeekFlags) Add(f SeekFlag) SeekFlags {
|
||||
return SeekFlags(flags(fs).add(int(f)))
|
||||
return SeekFlags(astikit.BitFlags(fs).Add(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs SeekFlags) Del(f SeekFlag) SeekFlags {
|
||||
return SeekFlags(flags(fs).del(int(f)))
|
||||
return SeekFlags(astikit.BitFlags(fs).Del(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs SeekFlags) Has(f SeekFlag) bool { return flags(fs).has(int(f)) }
|
||||
func (fs SeekFlags) Has(f SeekFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||
|
||||
type StreamEventFlags flags
|
||||
type StreamEventFlags astikit.BitFlags
|
||||
|
||||
func NewStreamEventFlags(fs ...StreamEventFlag) StreamEventFlags {
|
||||
o := StreamEventFlags(0)
|
||||
@@ -272,11 +276,11 @@ func NewStreamEventFlags(fs ...StreamEventFlag) StreamEventFlags {
|
||||
}
|
||||
|
||||
func (fs StreamEventFlags) Add(f StreamEventFlag) StreamEventFlags {
|
||||
return StreamEventFlags(flags(fs).add(int(f)))
|
||||
return StreamEventFlags(astikit.BitFlags(fs).Add(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs StreamEventFlags) Del(f StreamEventFlag) StreamEventFlags {
|
||||
return StreamEventFlags(flags(fs).del(int(f)))
|
||||
return StreamEventFlags(astikit.BitFlags(fs).Del(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs StreamEventFlags) Has(f StreamEventFlag) bool { return flags(fs).has(int(f)) }
|
||||
func (fs StreamEventFlags) Has(f StreamEventFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||
|
9
go.mod
9
go.mod
@@ -3,9 +3,14 @@ module github.com/asticode/go-astiav
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/asticode/go-astikit v0.28.2
|
||||
github.com/asticode/go-astikit v0.42.0
|
||||
github.com/stretchr/testify v1.7.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/stretchr/testify v1.7.0
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
)
|
||||
|
||||
//replace github.com/asticode/go-astikit => ../go-astikit
|
||||
|
4
go.sum
4
go.sum
@@ -1,5 +1,5 @@
|
||||
github.com/asticode/go-astikit v0.28.2 h1:c2shjqarbZwcQGQ7GPfchG2sSOL/7NHGbdgHTx43RH8=
|
||||
github.com/asticode/go-astikit v0.28.2/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0=
|
||||
github.com/asticode/go-astikit v0.42.0 h1:pnir/2KLUSr0527Tv908iAH6EGYYrYta132vvjXsH5w=
|
||||
github.com/asticode/go-astikit v0.42.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
|
@@ -32,8 +32,12 @@ var list = []listItem{
|
||||
|
||||
var tmpl = `// Code generated by astiav. DO NOT EDIT.
|
||||
package astiav
|
||||
|
||||
import (
|
||||
"github.com/asticode/go-astikit"
|
||||
)
|
||||
{{ range $val := . }}
|
||||
type {{ $val.Name }}Flags{{ $val.Suffix }} flags
|
||||
type {{ $val.Name }}Flags{{ $val.Suffix }} astikit.BitFlags
|
||||
|
||||
func New{{ $val.Name }}Flags{{ $val.Suffix }}(fs ...{{ $val.Name }}Flag{{ $val.Suffix }}) {{ $val.Name }}Flags{{ $val.Suffix }} {
|
||||
o := {{ $val.Name }}Flags{{ $val.Suffix }}(0)
|
||||
@@ -44,14 +48,14 @@ func New{{ $val.Name }}Flags{{ $val.Suffix }}(fs ...{{ $val.Name }}Flag{{ $val.S
|
||||
}
|
||||
|
||||
func (fs {{ $val.Name }}Flags{{ $val.Suffix }}) Add(f {{ $val.Name }}Flag{{ $val.Suffix }}) {{ $val.Name }}Flags{{ $val.Suffix }} {
|
||||
return {{ $val.Name }}Flags{{ $val.Suffix }}(flags(fs).add(int(f)))
|
||||
return {{ $val.Name }}Flags{{ $val.Suffix }}(astikit.BitFlags(fs).Add(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs {{ $val.Name }}Flags{{ $val.Suffix }}) Del(f {{ $val.Name }}Flag{{ $val.Suffix }}) {{ $val.Name }}Flags{{ $val.Suffix }} {
|
||||
return {{ $val.Name }}Flags{{ $val.Suffix }}(flags(fs).del(int(f)))
|
||||
return {{ $val.Name }}Flags{{ $val.Suffix }}(astikit.BitFlags(fs).Del(uint64(f)))
|
||||
}
|
||||
|
||||
func (fs {{ $val.Name }}Flags{{ $val.Suffix }}) Has(f {{ $val.Name }}Flag{{ $val.Suffix }}) bool { return flags(fs).has(int(f)) }
|
||||
func (fs {{ $val.Name }}Flags{{ $val.Suffix }}) Has(f {{ $val.Name }}Flag{{ $val.Suffix }}) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||
{{ end }}`
|
||||
|
||||
var tmplTest = `// Code generated by astiav. DO NOT EDIT.
|
||||
|
Reference in New Issue
Block a user