MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / MarshalJSON

Method MarshalJSON

libs/bits/bit_array.go:368–386  ·  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

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

Callers

nothing calls this directly

Calls 3

getIndexMethod · 0.95
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected