MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / NewObject

Method NewObject

pkg/util/json/json.go:511–535  ·  view source on GitHub ↗

NewObject creates a new JSON object with the specified new key-values. The keys of newData must be exactly the same as the newKeys supplied to the constructor.

(newData map[string]JSON)

Source from the content-addressed store, hash-verified

509// keys of newData must be exactly the same as the newKeys supplied to the
510// constructor.
511func (po *PartialObject) NewObject(newData map[string]JSON) (JSON, error) {
512 if len(newData) != len(po.allowedNewKeys) {
513 return nil, errors.AssertionFailedf(
514 "expected all %d keys to be updated, %d updated",
515 len(po.allowedNewKeys), len(newData))
516 }
517
518 pairs := make([]jsonKeyValuePair, len(po.basePairs)+len(newData))
519
520 for _, p := range po.basePairs {
521 pairs[po.keyOrd[string(p.k)]] = p
522 }
523
524 for k, v := range newData {
525 if _, ok := po.allowedNewKeys[k]; !ok {
526 return nil, errors.AssertionFailedf("unknown new key %s", k)
527 }
528 if _, ok := po.keyOrd[k]; !ok {
529 return nil, errors.AssertionFailedf("unknown key %s", k)
530 }
531 pairs[po.keyOrd[k]] = jsonKeyValuePair{k: jsonString(k), v: v}
532 }
533
534 return jsonObject(pairs), nil
535}
536
537// pairSorter sorts and uniqueifies JSON pairs. In order to keep
538// the last one for pairs with the same key while sort.Sort is

Callers

nothing calls this directly

Calls 2

jsonStringTypeAlias · 0.85
jsonObjectTypeAlias · 0.85

Tested by

no test coverage detected