MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / unmarshalDocument

Function unmarshalDocument

db/document.go:482–500  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
482func 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
502func 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 {

Callers 9

ResyncDocumentMethod · 0.85
RepairJobRevTreeCyclesFunction · 0.85
migrateMetadataMethod · 0.85
GetDocumentWithRawMethod · 0.85
Test_getUpdatedDocumentFunction · 0.85

Calls 7

SetAttachmentsMethod · 0.95
AttachmentsMethod · 0.95
JSONDecoderFunction · 0.92
NewDocumentFunction · 0.85
mergeAttachmentsFunction · 0.85
UseNumberMethod · 0.80
DecodeMethod · 0.65

Tested by 3

Test_getUpdatedDocumentFunction · 0.68