Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
enum key generation (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitiko authored Jul 12, 2021
1 parent 6b3da10 commit 7faa3a9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions state/mapping/state_mapping_opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/timestamp"

"github.com/s7techlab/cckit/state"
)

Expand Down Expand Up @@ -223,8 +224,15 @@ func keysFromValue(v reflect.Value) ([]state.Key, error) {
func keyFromValue(v reflect.Value) (state.Key, error) {
var key state.Key

if v.Kind() == reflect.Ptr {
switch v.Kind() {

// enum in protobuf
case reflect.Int32:
if stringer, ok := v.Interface().(fmt.Stringer); ok {
return state.Key{stringer.String()}, nil
}

case reflect.Ptr:
// todo: extract key producer and add custom serializers
switch val := v.Interface().(type) {

Expand All @@ -250,7 +258,6 @@ func keyFromValue(v reflect.Value) (state.Key, error) {
}

return key, nil

}
}

Expand Down

0 comments on commit 7faa3a9

Please sign in to comment.