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

Method UnmarshalJSON

libs/bits/bit_array.go:392–419  ·  view source on GitHub ↗

UnmarshalJSON implements json.Unmarshaler interface by unmarshaling a custom JSON description.

(bz []byte)

Source from the content-addressed store, hash-verified

390// UnmarshalJSON implements json.Unmarshaler interface by unmarshaling a custom
391// JSON description.
392func (bA *BitArray) UnmarshalJSON(bz []byte) error {
393 b := string(bz)
394 if b == "null" {
395 // This is required e.g. for encoding/json when decoding
396 // into a pointer with pre-allocated BitArray.
397 bA.Bits = 0
398 bA.Elems = nil
399 return nil
400 }
401
402 // Validate 'b'.
403 match := bitArrayJSONRegexp.FindStringSubmatch(b)
404 if match == nil {
405 return fmt.Errorf("bitArray in JSON should be a string of format %q but got %s", bitArrayJSONRegexp.String(), b)
406 }
407 bits := match[1]
408
409 // Construct new BitArray and copy over.
410 numBits := len(bits)
411 bA2 := NewBitArray(numBits)
412 for i := 0; i < numBits; i++ {
413 if bits[i] == 'x' {
414 bA2.SetIndex(i, true)
415 }
416 }
417 *bA = *bA2 //nolint:govet
418 return nil
419}
420
421// ToProto converts BitArray to protobuf
422func (bA *BitArray) ToProto() *tmprotobits.BitArray {

Callers

nothing calls this directly

Calls 3

SetIndexMethod · 0.95
NewBitArrayFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected