MCPcopy Create free account
hub / github.com/aws/smithy-go / decodeInt

Method decodeInt

document/cbor/decode.go:87–117  ·  view source on GitHub ↗
(v cbor.Value, rv reflect.Value)

Source from the content-addressed store, hash-verified

85}
86
87func (d *decoder) decodeInt(v cbor.Value, rv reflect.Value) error {
88 switch rv.Kind() {
89 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
90 i, err := cbor.AsInt64(v)
91 if err != nil {
92 return err
93 }
94 if rv.OverflowInt(i) {
95 return &document.UnmarshalTypeError{
96 Value: fmt.Sprintf("number overflow, %d", i),
97 Type: rv.Type(),
98 }
99 }
100 rv.SetInt(i)
101 case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
102 u, ok := v.(cbor.Uint)
103 if !ok {
104 return &document.UnmarshalTypeError{Value: "number", Type: rv.Type()}
105 }
106 if rv.OverflowUint(uint64(u)) {
107 return &document.UnmarshalTypeError{
108 Value: fmt.Sprintf("number overflow, %d", u),
109 Type: rv.Type(),
110 }
111 }
112 rv.SetUint(uint64(u))
113 default:
114 return &document.UnmarshalTypeError{Value: "number", Type: rv.Type()}
115 }
116 return nil
117}
118
119func (d *decoder) decodeNil(rv reflect.Value) error {
120 if rv.IsValid() && rv.CanSet() {

Callers 1

decodeMethod · 0.95

Calls 1

AsInt64Function · 0.92

Tested by

no test coverage detected