mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 03:38:35 +00:00
21 lines
391 B
Go
21 lines
391 B
Go
|
package opcode
|
||
|
|
||
|
import "errors"
|
||
|
|
||
|
var stringToOpcode = make(map[string]Opcode)
|
||
|
|
||
|
func init() {
|
||
|
for i := 0; i < 255; i++ {
|
||
|
op := Opcode(i)
|
||
|
stringToOpcode[op.String()] = op
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// FromString converts string representation to and opcode itself.
|
||
|
func FromString(s string) (Opcode, error) {
|
||
|
if op, ok := stringToOpcode[s]; ok {
|
||
|
return op, nil
|
||
|
}
|
||
|
return 0, errors.New("invalid opcode")
|
||
|
}
|