-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapper_int32.go
26 lines (22 loc) · 908 Bytes
/
mapper_int32.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package mapper_protobuf
import (
"github.com/peace0phmind/bud/structure"
"google.golang.org/protobuf/types/known/wrapperspb"
"reflect"
)
func init() {
structure.RegisterMapper[wrapperspb.Int32Value, int32](int32value2intMapper)
structure.RegisterMapper[int32, wrapperspb.Int32Value](int2int32valueMapper)
structure.RegisterMapper[wrapperspb.Int32Value, int16](int32value2intMapper)
structure.RegisterMapper[int16, wrapperspb.Int32Value](int2int32valueMapper)
structure.RegisterMapper[wrapperspb.Int32Value, int8](int32value2intMapper)
structure.RegisterMapper[int8, wrapperspb.Int32Value](int2int32valueMapper)
}
func int32value2intMapper(from reflect.Value, to reflect.Value) error {
to.SetInt(int64(from.Interface().(wrapperspb.Int32Value).Value))
return nil
}
func int2int32valueMapper(from reflect.Value, to reflect.Value) error {
to.FieldByName("value").SetInt(from.Int())
return nil
}