@@ -79,7 +79,21 @@ func NewWrapper(key string, meta *Meta, format uint8, data []byte) (*Wrapper, er
79
79
}, nil
80
80
}
81
81
82
- // Marshal marshals the object, without the database key or metadata.
82
+ // NewWrapperFromDatabase returns a new record wrapper for the given data.
83
+ func NewWrapperFromDatabase (dbName , dbKey string , meta * Meta , format uint8 , data []byte ) (* Wrapper , error ) {
84
+ return & Wrapper {
85
+ Base {
86
+ dbName : dbName ,
87
+ dbKey : dbKey ,
88
+ meta : meta ,
89
+ },
90
+ sync.Mutex {},
91
+ format ,
92
+ data ,
93
+ }, nil
94
+ }
95
+
96
+ // Marshal marshals the format and data.
83
97
func (w * Wrapper ) Marshal (r Record , format uint8 ) ([]byte , error ) {
84
98
if w .Meta () == nil {
85
99
return nil , errors .New ("missing meta" )
@@ -100,7 +114,24 @@ func (w *Wrapper) Marshal(r Record, format uint8) ([]byte, error) {
100
114
return data , nil
101
115
}
102
116
103
- // MarshalRecord packs the object, including metadata, into a byte array for saving in a database.
117
+ // MarshalDataOnly marshals the data only.
118
+ func (w * Wrapper ) MarshalDataOnly (self Record , format uint8 ) ([]byte , error ) {
119
+ if w .Meta () == nil {
120
+ return nil , errors .New ("missing meta" )
121
+ }
122
+
123
+ if w .Meta ().Deleted > 0 {
124
+ return nil , nil
125
+ }
126
+
127
+ if format != dsd .AUTO && format != w .Format {
128
+ return nil , errors .New ("could not dump model, wrapped object format mismatch" )
129
+ }
130
+
131
+ return w .Data , nil
132
+ }
133
+
134
+ // MarshalRecord marshals the data, format and metadata.
104
135
func (w * Wrapper ) MarshalRecord (r Record ) ([]byte , error ) {
105
136
// Duplication necessary, as the version from Base would call Base.Marshal instead of Wrapper.Marshal
106
137
0 commit comments