Unmarshals a document from JSON data. The doc ID isn't in the data and must be given. Uses decode to ensure UseNumber handling is applied to numbers in the body.
(docid string, data []byte)
| 480 | // Unmarshals a document from JSON data. The doc ID isn't in the data and must be given. Uses decode to ensure |
| 481 | // UseNumber handling is applied to numbers in the body. |
| 482 | func unmarshalDocument(docid string, data []byte) (*Document, error) { |
| 483 | doc := NewDocument(docid) |
| 484 | if len(data) > 0 { |
| 485 | decoder := base.JSONDecoder(bytes.NewReader(data)) |
| 486 | decoder.UseNumber() |
| 487 | if err := decoder.Decode(doc); err != nil { |
| 488 | return nil, pkgerrors.Wrapf(err, "Error unmarshalling doc.") |
| 489 | } |
| 490 | |
| 491 | if doc != nil && doc.Deleted_OLD { |
| 492 | doc.Deleted_OLD = false |
| 493 | doc.Flags |= channels.Deleted // Backward compatibility with old Deleted property |
| 494 | } |
| 495 | doc.SetAttachments(mergeAttachments(doc.SyncData.AttachmentsPre4dot0, doc.Attachments())) |
| 496 | doc.SyncData.AttachmentsPre4dot0 = nil |
| 497 | |
| 498 | } |
| 499 | return doc, nil |
| 500 | } |
| 501 | |
| 502 | func unmarshalDocumentWithXattrs(ctx context.Context, docid string, data, syncXattrData, hlvXattrData, mouXattrData, userXattrData, revSeqNo []byte, globalSyncData []byte, cas uint64, unmarshalLevel DocumentUnmarshalLevel) (doc *Document, err error) { |
| 503 | if len(syncXattrData) == 0 && len(hlvXattrData) == 0 { |