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

Function encodeDoc

docstore/gcpfirestore/codec.go:34–45  ·  view source on GitHub ↗

encodeDoc encodes a driver.Document into Firestore's representation. A Firestore document (*pb.Document) is just a Go map from strings to *pb.Values.

(doc driver.Document, nameField string)

Source from the content-addressed store, hash-verified

32// encodeDoc encodes a driver.Document into Firestore's representation.
33// A Firestore document (*pb.Document) is just a Go map from strings to *pb.Values.
34func encodeDoc(doc driver.Document, nameField string) (*pb.Document, error) {
35 var e encoder
36 if err := doc.Encode(&e); err != nil {
37 return nil, err
38 }
39 fields := e.pv.GetMapValue().Fields
40 // Do not put the name field in the document itself.
41 if nameField != "" {
42 delete(fields, nameField)
43 }
44 return &pb.Document{Fields: fields}, nil
45}
46
47// encodeValue encodes a Go value as a Firestore Value.
48// The Firestore proto definition for Value is a oneof of various types,

Callers 2

putWriteMethod · 0.70
TestCodecSpecialFunction · 0.70

Calls 1

EncodeMethod · 0.45

Tested by 1

TestCodecSpecialFunction · 0.56