@@ -24,6 +24,7 @@ import (
2424 "context"
2525 "io"
2626 "net/http"
27+ "reflect"
2728
2829 "github.com/pkg/errors"
2930
@@ -132,7 +133,7 @@ func newCollectionDocumentReplaceResponseReader(array *connection.Array, options
132133 c .response .Old = newUnmarshalInto (c .options .OldObject )
133134 c .response .New = newUnmarshalInto (c .options .NewObject )
134135 }
135-
136+ c . ReadAllReader = shared. ReadAllReader [ CollectionDocumentReplaceResponse , * collectionDocumentReplaceResponseReader ]{ Reader : c }
136137 return c
137138}
138139
@@ -147,6 +148,12 @@ type collectionDocumentReplaceResponseReader struct {
147148 Old * UnmarshalInto `json:"old,omitempty"`
148149 New * UnmarshalInto `json:"new,omitempty"`
149150 }
151+ shared.ReadAllReader [CollectionDocumentReplaceResponse , * collectionDocumentReplaceResponseReader ]
152+
153+ // Cache for len() method
154+ cachedResults []CollectionDocumentReplaceResponse
155+ cachedErrors []error
156+ cached bool
150157}
151158
152159func (c * collectionDocumentReplaceResponseReader ) Read () (CollectionDocumentReplaceResponse , error ) {
@@ -157,8 +164,15 @@ func (c *collectionDocumentReplaceResponseReader) Read() (CollectionDocumentRepl
157164 var meta CollectionDocumentReplaceResponse
158165
159166 if c .options != nil {
160- meta .Old = c .options .OldObject
161- meta .New = c .options .NewObject
167+ // Create new instances for each document to avoid reusing the same pointers
168+ if c .options .OldObject != nil {
169+ oldObjectType := reflect .TypeOf (c .options .OldObject ).Elem ()
170+ meta .Old = reflect .New (oldObjectType ).Interface ()
171+ }
172+ if c .options .NewObject != nil {
173+ newObjectType := reflect .TypeOf (c .options .NewObject ).Elem ()
174+ meta .New = reflect .New (newObjectType ).Interface ()
175+ }
162176 }
163177
164178 c .response .DocumentMetaWithOldRev = & meta .DocumentMetaWithOldRev
@@ -171,9 +185,24 @@ func (c *collectionDocumentReplaceResponseReader) Read() (CollectionDocumentRepl
171185 return CollectionDocumentReplaceResponse {}, err
172186 }
173187
188+ // Update meta with the unmarshaled data
189+ meta .DocumentMetaWithOldRev = * c .response .DocumentMetaWithOldRev
190+ meta .ResponseStruct = * c .response .ResponseStruct
191+ meta .Old = c .response .Old
192+ meta .New = c .response .New
193+
174194 if meta .Error != nil && * meta .Error {
175195 return meta , meta .AsArangoError ()
176196 }
177197
178198 return meta , nil
179199}
200+
201+ // Len returns the number of items in the response
202+ func (c * collectionDocumentReplaceResponseReader ) Len () int {
203+ if ! c .cached {
204+ c .cachedResults , c .cachedErrors = c .ReadAll ()
205+ c .cached = true
206+ }
207+ return len (c .cachedResults )
208+ }
0 commit comments