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

Method MarshalJSON

libs/bits/bit_array.go:373–391  ·  view source on GitHub ↗

MarshalJSON implements json.Marshaler interface by marshaling bit array using a custom format: a string of '-' or 'x' where 'x' denotes the 1 bit.

()

Source from the content-addressed store, hash-verified

371// MarshalJSON implements json.Marshaler interface by marshaling bit array
372// using a custom format: a string of '-' or 'x' where 'x' denotes the 1 bit.
373func (bA *BitArray) MarshalJSON() ([]byte, error) {
374 if bA == nil {
375 return []byte("null"), nil
376 }
377
378 bA.mtx.Lock()
379 defer bA.mtx.Unlock()
380
381 bits := `"`
382 for i := 0; i < bA.Bits; i++ {
383 if bA.getIndex(i) {
384 bits += `x`
385 } else {
386 bits += `_`
387 }
388 }
389 bits += `"`
390 return []byte(bits), nil
391}
392
393var bitArrayJSONRegexp = regexp.MustCompile(`\A"([_x]*)"\z`)
394

Callers

nothing calls this directly

Calls 3

getIndexMethod · 0.95
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected