enhance(crc):CRC系列校验算法增加使用大端序或者小端序输出的功能。
This commit is contained in:
28
types/endian.go
Normal file
28
types/endian.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package types
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Endian string
|
||||
|
||||
const (
|
||||
BigEndian Endian = "big"
|
||||
LittleEndian Endian = "little"
|
||||
)
|
||||
|
||||
func (e *Endian) String() string {
|
||||
return string(*e)
|
||||
}
|
||||
|
||||
func (e *Endian) Set(s string) error {
|
||||
switch s {
|
||||
case "big", "little":
|
||||
*e = Endian(s)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("不支持的字节序:%s", s)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Endian) Type() string {
|
||||
return "Endian"
|
||||
}
|
Reference in New Issue
Block a user