IsComposite implements the CompositeDatum interface.
()
| 3996 | |
| 3997 | // IsComposite implements the CompositeDatum interface. |
| 3998 | func (d *DJSON) IsComposite() bool { |
| 3999 | switch d.JSON.Type() { |
| 4000 | case json.NumberJSONType: |
| 4001 | dec, ok := d.JSON.AsDecimal() |
| 4002 | if !ok { |
| 4003 | panic(errors.AssertionFailedf("could not convert into JSON Decimal")) |
| 4004 | } |
| 4005 | DDec := DDecimal{Decimal: *dec} |
| 4006 | return DDec.IsComposite() |
| 4007 | case json.ArrayJSONType: |
| 4008 | jsonArray, ok := d.AsArray() |
| 4009 | if !ok { |
| 4010 | panic(errors.AssertionFailedf("could not extract the JSON Array")) |
| 4011 | } |
| 4012 | for _, elem := range jsonArray { |
| 4013 | dJsonVal := DJSON{elem} |
| 4014 | if dJsonVal.IsComposite() { |
| 4015 | return true |
| 4016 | } |
| 4017 | } |
| 4018 | case json.ObjectJSONType: |
| 4019 | if it, err := d.ObjectIter(); it != nil && err == nil { |
| 4020 | // Assumption: no collated strings are present as JSON keys. |
| 4021 | // Thus, JSON keys are not being checked if they are |
| 4022 | // composite or not. |
| 4023 | for it.Next() { |
| 4024 | valDJSON := NewDJSON(it.Value()) |
| 4025 | if valDJSON.IsComposite() { |
| 4026 | return true |
| 4027 | } |
| 4028 | } |
| 4029 | } else if err != nil { |
| 4030 | panic(errors.NewAssertionErrorWithWrappedErrf(err, "could not receive an ObjectKeyIterator")) |
| 4031 | } |
| 4032 | } |
| 4033 | return false |
| 4034 | } |
| 4035 | |
| 4036 | // ParseDJSON takes a string of JSON and returns a DJSON value. |
| 4037 | func ParseDJSON(s string) (Datum, error) { |
nothing calls this directly
no test coverage detected