MCPcopy Create free account
hub / github.com/google/go-cloud / decodeDoc

Function decodeDoc

docstore/memdocstore/codec.go:98–120  ·  view source on GitHub ↗

decodeDoc decodes m into ddoc.

(m storedDoc, ddoc driver.Document, fps [][]string)

Source from the content-addressed store, hash-verified

96
97// decodeDoc decodes m into ddoc.
98func decodeDoc(m storedDoc, ddoc driver.Document, fps [][]string) error {
99 var m2 map[string]any
100 if len(fps) == 0 {
101 m2 = m
102 } else {
103 // Make a document to decode from that has only the field paths.
104 // (We don't need the key field because ddoc must already have it.)
105 m2 = map[string]any{}
106 for _, fp := range fps {
107 val, err := getAtFieldPath(m, fp, false)
108 if err != nil {
109 if gcerrors.Code(err) == gcerrors.NotFound {
110 continue
111 }
112 return err
113 }
114 if err := setAtFieldPath(m2, fp, val); err != nil {
115 return err
116 }
117 }
118 }
119 return ddoc.Decode(decoder{m2})
120}
121
122type decoder struct {
123 val any

Callers 3

NextMethod · 0.70
runActionMethod · 0.70
TestDecodeDocFunction · 0.70

Calls 4

CodeFunction · 0.92
getAtFieldPathFunction · 0.85
setAtFieldPathFunction · 0.70
DecodeMethod · 0.45

Tested by 1

TestDecodeDocFunction · 0.56