Turn "{h:123;m:345}" into 123, 345. Return maxUInt if length is unspecified.
(c string)
| 158 | // |
| 159 | // Return maxUInt if length is unspecified. |
| 160 | func parseHeaderMessageLengthConfig(c string) (hdrLenStr, msgLenStr uint64, err error) { |
| 161 | if c == "" { |
| 162 | return maxUInt, maxUInt, nil |
| 163 | } |
| 164 | // Header config only. |
| 165 | if match := headerConfigRegexp.FindStringSubmatch(c); match != nil { |
| 166 | if s := match[1]; s != "" { |
| 167 | hdrLenStr, err = strconv.ParseUint(s, 10, 64) |
| 168 | if err != nil { |
| 169 | return 0, 0, fmt.Errorf("failed to convert %q to uint", s) |
| 170 | } |
| 171 | return hdrLenStr, 0, nil |
| 172 | } |
| 173 | return maxUInt, 0, nil |
| 174 | } |
| 175 | |
| 176 | // Message config only. |
| 177 | if match := messageConfigRegexp.FindStringSubmatch(c); match != nil { |
| 178 | if s := match[1]; s != "" { |
| 179 | msgLenStr, err = strconv.ParseUint(s, 10, 64) |
| 180 | if err != nil { |
| 181 | return 0, 0, fmt.Errorf("failed to convert %q to uint", s) |
| 182 | } |
| 183 | return 0, msgLenStr, nil |
| 184 | } |
| 185 | return 0, maxUInt, nil |
| 186 | } |
| 187 | |
| 188 | // Header and message config both. |
| 189 | if match := headerMessageConfigRegexp.FindStringSubmatch(c); match != nil { |
| 190 | // Both hdr and msg are specified, but one or two of them might be empty. |
| 191 | hdrLenStr = maxUInt |
| 192 | msgLenStr = maxUInt |
| 193 | if s := match[1]; s != "" { |
| 194 | hdrLenStr, err = strconv.ParseUint(s, 10, 64) |
| 195 | if err != nil { |
| 196 | return 0, 0, fmt.Errorf("failed to convert %q to uint", s) |
| 197 | } |
| 198 | } |
| 199 | if s := match[2]; s != "" { |
| 200 | msgLenStr, err = strconv.ParseUint(s, 10, 64) |
| 201 | if err != nil { |
| 202 | return 0, 0, fmt.Errorf("failed to convert %q to uint", s) |
| 203 | } |
| 204 | } |
| 205 | return hdrLenStr, msgLenStr, nil |
| 206 | } |
| 207 | return 0, 0, fmt.Errorf("%q contains invalid substring", c) |
| 208 | } |