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)
| 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. |
| 34 | func 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, |