1 /* Stores a Block Locator Digest compactly. Can be used as a map key. */
11 // Stores a Block Locator Digest compactly, up to 128 bits.
12 // Can be used as a map key.
13 type BlockDigest struct {
18 func (d BlockDigest) String() string {
19 return fmt.Sprintf("%016x%016x", d.h, d.l)
22 // Will create a new BlockDigest unless an error is encountered.
23 func FromString(s string) (dig BlockDigest, err error) {
25 err = fmt.Errorf("Block digest should be exactly 32 characters but this one is %d: %s", len(s), s)
30 d.h, err = strconv.ParseUint(s[:16], 16, 64)
34 d.l, err = strconv.ParseUint(s[16:], 16, 64)
42 // Will fatal with the error if an error is encountered
43 func AssertFromString(s string) BlockDigest {
44 d, err := FromString(s)
46 log.Fatalf("Error creating BlockDigest from %s: %v", s, err)