Skip to content

Commit

Permalink
Merge pull request stellar#7 from tinco/master
Browse files Browse the repository at this point in the history
allow arm switches to be uint
  • Loading branch information
nullstyle committed Jul 26, 2018
2 parents a875e7c + e7f5a80 commit f4c839f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion xdr3/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,13 @@ func (d *Decoder) decodeUnion(v reflect.Value) (int, error) {
return n, err
}

vs.SetInt(int64(i))
kind := vs.Kind()
if kind == reflect.Uint || kind == reflect.Uint8 || kind == reflect.Uint16 ||
kind == reflect.Uint32 || kind == reflect.Uint64 {
vs.SetUint(uint64(i))
} else {
vs.SetInt(int64(i))
}

arm, ok := u.ArmForSwitch(i)

Expand Down
9 changes: 8 additions & 1 deletion xdr3/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,14 @@ func (enc *Encoder) encodeUnion(v reflect.Value) (int, error) {
return n, err
}

sw := int32(vs.Int())
kind := vs.Kind()
var sw int32
if kind == reflect.Uint || kind == reflect.Uint8 || kind == reflect.Uint16 ||
kind == reflect.Uint32 || kind == reflect.Uint64 {
sw = int32(vs.Uint())
} else {
sw = int32(vs.Int())
}
arm, ok := u.ArmForSwitch(sw)

// void arm, we're done
Expand Down

0 comments on commit f4c839f

Please sign in to comment.