(s string)
| 326 | } |
| 327 | |
| 328 | func parseFromBinary(s string) (res BitArray, err error) { |
| 329 | words, lastBitsUsed := EncodingPartsForBitLen(uint(len(s))) |
| 330 | |
| 331 | // Parse the bits. |
| 332 | wordIdx := 0 |
| 333 | bitIdx := uint(0) |
| 334 | curWord := word(0) |
| 335 | for _, c := range s { |
| 336 | val := word(c - '0') |
| 337 | bitVal := val & 1 |
| 338 | if bitVal != val { |
| 339 | // Note: the prefix "could not parse" is important as it is used |
| 340 | // to detect parsing errors in tests. |
| 341 | err := fmt.Errorf(`could not parse string as bit array: "%c" is not a valid binary digit`, c) |
| 342 | return res, pgerror.WithCandidateCode(err, pgcode.InvalidTextRepresentation) |
| 343 | } |
| 344 | curWord |= bitVal << (63 - bitIdx) |
| 345 | bitIdx = (bitIdx + 1) % numBitsPerWord |
| 346 | if bitIdx == 0 { |
| 347 | words[wordIdx] = curWord |
| 348 | curWord = 0 |
| 349 | wordIdx++ |
| 350 | } |
| 351 | } |
| 352 | if bitIdx > 0 { |
| 353 | // Ensure the last word is stored. |
| 354 | words[wordIdx] = curWord |
| 355 | } |
| 356 | |
| 357 | return FromEncodingParts(words, lastBitsUsed) |
| 358 | } |
| 359 | |
| 360 | func parseFromHex(s string) (res BitArray, err error) { |
| 361 | words, lastBitsUsed := EncodingPartsForBitLen(uint(len(s)) * 4) |
no test coverage detected
searching dependent graphs…