MCPcopy
hub / github.com/grpc/grpc-go / decodeTimeout

Function decodeTimeout

internal/transport/http_util.go:188–212  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

186}
187
188func decodeTimeout(s string) (time.Duration, error) {
189 size := len(s)
190 if size < 2 {
191 return 0, fmt.Errorf("transport: timeout string is too short: %q", s)
192 }
193 if size > 9 {
194 // Spec allows for 8 digits plus the unit.
195 return 0, fmt.Errorf("transport: timeout string is too long: %q", s)
196 }
197 unit := timeoutUnit(s[size-1])
198 d, ok := timeoutUnitToDuration(unit)
199 if !ok {
200 return 0, fmt.Errorf("transport: timeout unit is not recognized: %q", s)
201 }
202 t, err := strconv.ParseUint(s[:size-1], 10, 64)
203 if err != nil {
204 return 0, err
205 }
206 const maxHours = math.MaxInt64 / uint64(time.Hour)
207 if d == time.Hour && t > maxHours {
208 // This timeout would overflow math.MaxInt64; clamp it.
209 return time.Duration(math.MaxInt64), nil
210 }
211 return d * time.Duration(t), nil
212}
213
214const (
215 spaceByte = ' '

Callers 3

operateHeadersMethod · 0.85
TestDecodeTimeoutMethod · 0.85

Calls 3

timeoutUnitTypeAlias · 0.85
timeoutUnitToDurationFunction · 0.85
ErrorfMethod · 0.65

Tested by 1

TestDecodeTimeoutMethod · 0.68