microavia / messgen

MIT License
9 stars 11 forks source link

feature: initial constants generation support for golang #62

Closed onokonem closed 1 year ago

onokonem commented 1 year ago

golang code generator is extended with the possibility to generate constants

each constants group is presented as a type (name of the enum with Enum suffix) and bunch of the const values of this type. The const names are prepended with the type name.

String() method is defined for each const type as well as GetAll[enum name]()

example:

type SequenceStateEnum uint8

func (v SequenceStateEnum) String() string { return strconv.FormatUint(uint64(v), 10) }
func GetAllSequenceState() [4]SequenceStateEnum {
    return [4]SequenceStateEnum{SequenceStateNone, SequenceStateRunning, SequenceStateFinished, SequenceStateError}
}

const (
    SequenceStateNone     SequenceStateEnum = 0
    SequenceStateRunning  SequenceStateEnum = 1
    SequenceStateFinished SequenceStateEnum = 2
    SequenceStateError    SequenceStateEnum = 3
)