package types import ( "fmt" "archgrid.xyz/ag/toolsbox/hash/crc16" ) type CRC16Algorithm string const ( CRC16_CCITT CRC16Algorithm = "ccitt" CRC16_CCITT_FALSE CRC16Algorithm = "ccitt-false" CRC16_SCSI CRC16Algorithm = "scsi" CRC16_IBM CRC16Algorithm = "ibm" CRC16_MBUS CRC16Algorithm = "mbus" ) func (a *CRC16Algorithm) String() string { return string(*a) } func (a *CRC16Algorithm) Set(s string) error { switch s { case "ccitt", "ccitt-false", "scsi", "ibm", "mbus": *a = CRC16Algorithm(s) return nil default: return fmt.Errorf("不支持的CRC16算法:%s", s) } } func (a *CRC16Algorithm) Type() string { return "CRC16Algorithm" } func (a CRC16Algorithm) IntoCRC16Mode() crc16.CRC16Mode { switch a { case CRC16_CCITT: return crc16.CCITT case CRC16_CCITT_FALSE: return crc16.CCITT_FALSE case CRC16_SCSI: return crc16.SCSI case CRC16_IBM: return crc16.IBM case CRC16_MBUS: return crc16.MBUS default: return crc16.IBM } }