MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / parseFromHex

Function parseFromHex

pkg/util/bitarray/bitarray.go:360–395  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

358}
359
360func parseFromHex(s string) (res BitArray, err error) {
361 words, lastBitsUsed := EncodingPartsForBitLen(uint(len(s)) * 4)
362
363 // Parse the bits.
364 wordIdx := 0
365 bitIdx := uint(0)
366 curWord := word(0)
367 for _, c := range s {
368 var bitVal word
369 if c >= '0' && c <= '9' {
370 bitVal = word(c - '0')
371 } else if c >= 'a' && c <= 'f' {
372 bitVal = word(c-'a') + 10
373 } else if c >= 'A' && c <= 'F' {
374 bitVal = word(c-'A') + 10
375 } else {
376 // Note: the prefix "could not parse" is important as it is used
377 // to detect parsing errors in tests.
378 err := fmt.Errorf(`could not parse string as bit array: "%c" is not a valid hexadecimal digit`, c)
379 return res, pgerror.WithCandidateCode(err, pgcode.InvalidTextRepresentation)
380 }
381 curWord |= bitVal << (60 - bitIdx)
382 bitIdx = (bitIdx + 4) % numBitsPerWord
383 if bitIdx == 0 {
384 words[wordIdx] = curWord
385 curWord = 0
386 wordIdx++
387 }
388 }
389 if bitIdx > 0 {
390 // Ensure the last word is stored.
391 words[wordIdx] = curWord
392 }
393
394 return FromEncodingParts(words, lastBitsUsed)
395}
396
397// Concat concatenates two bit arrays.
398func Concat(lhs, rhs BitArray) BitArray {

Callers 1

ParseFunction · 0.85

Calls 4

WithCandidateCodeFunction · 0.92
EncodingPartsForBitLenFunction · 0.85
FromEncodingPartsFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…