MCPcopy Create free account
hub / github.com/tendermint/tendermint / FromProto

Method FromProto

libs/bits/bit_array.go:443–469  ·  view source on GitHub ↗

FromProto sets BitArray to the given protoBitArray. It returns an error if protoBitArray is invalid.

(protoBitArray *tmprotobits.BitArray)

Source from the content-addressed store, hash-verified

441// FromProto sets BitArray to the given protoBitArray. It returns an error if
442// protoBitArray is invalid.
443func (bA *BitArray) FromProto(protoBitArray *tmprotobits.BitArray) error {
444 if protoBitArray == nil {
445 return nil
446 }
447
448 // Validate protoBitArray.
449 if protoBitArray.Bits < 0 {
450 return errors.New("negative Bits")
451 }
452 // #[32bit]
453 if protoBitArray.Bits > math.MaxInt32 { // prevent overflow on 32bit systems
454 return errors.New("too many Bits")
455 }
456 if got, exp := len(protoBitArray.Elems), numElems(int(protoBitArray.Bits)); got != exp {
457 return fmt.Errorf("invalid number of Elems: got %d, but exp %d", got, exp)
458 }
459
460 bA.mtx.Lock()
461 defer bA.mtx.Unlock()
462
463 ec := make([]uint64, len(protoBitArray.Elems))
464 copy(ec, protoBitArray.Elems)
465
466 bA.Bits = int(protoBitArray.Bits)
467 bA.Elems = ec
468 return nil
469}
470
471func numElems(bits int) int {
472 return (bits + 63) / 64

Callers 2

TestBitArrayToFromProtoFunction · 0.45
TestBitArrayFromProtoFunction · 0.45

Calls 3

numElemsFunction · 0.85
LockMethod · 0.65
UnlockMethod · 0.65

Tested by 2

TestBitArrayToFromProtoFunction · 0.36
TestBitArrayFromProtoFunction · 0.36