ag_tools/types/crc8.go

68 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package types
import (
"fmt"
"archgrid.xyz/ag/toolsbox/hash/crc8"
)
type CRC8Algorithm string
const (
CRC8_Origin CRC8Algorithm = "crc8"
CRC8_CDMA2000 CRC8Algorithm = "cdma2000"
CRC8_DARC CRC8Algorithm = "darc"
CRC8_DVB_S2 CRC8Algorithm = "dvb-s2"
CRC8_EBU CRC8Algorithm = "ebu"
CRC8_I_CODE CRC8Algorithm = "i-code"
CRC8_ITU CRC8Algorithm = "itu"
CRC8_MAXIM CRC8Algorithm = "maxim"
CRC8_ROHC CRC8Algorithm = "rohc"
CRC8_WCDMA CRC8Algorithm = "wcdma"
)
func (a *CRC8Algorithm) String() string {
return string(*a)
}
func (a *CRC8Algorithm) Set(s string) error {
switch s {
case "crc8", "cdma2000", "darc", "dvb-s2", "ebu", "i-code", "itu", "maxim", "rohc", "wcdma":
*a = CRC8Algorithm(s)
return nil
default:
return fmt.Errorf("不支持的CRC8算法%s", s)
}
}
func (a *CRC8Algorithm) Type() string {
return "CRC8Algorithm"
}
func (a CRC8Algorithm) IntoCRC8Mode() crc8.CRC8Mode {
switch a {
case CRC8_Origin:
return crc8.ORIGIN
case CRC8_CDMA2000:
return crc8.CDMA2000
case CRC8_DARC:
return crc8.DARC
case CRC8_DVB_S2:
return crc8.DVB_S2
case CRC8_EBU:
return crc8.EBU
case CRC8_I_CODE:
return crc8.I_CODE
case CRC8_ITU:
return crc8.ITU
case CRC8_MAXIM:
return crc8.MAXIM
case CRC8_ROHC:
return crc8.ROHC
case CRC8_WCDMA:
return crc8.WCDMA
default:
return crc8.ORIGIN
}
}