@@ -180,10 +180,15 @@ static boolean clientMetadataDocumentTooLarge(final BsonDocument document) {
180180 new BsonDocumentCodec ().encode (new BsonBinaryWriter (buffer ), document , EncoderContext .builder ().build ());
181181 return buffer .getPosition () > MAXIMUM_CLIENT_METADATA_ENCODED_SIZE ;
182182 }
183-
183+ /**
184+ * Modifies the given client metadata document by appending the driver information.
185+ * Driver name and version are appended atomically to the existing driver name and version if they do not exceed
186+ * {@value MAXIMUM_CLIENT_METADATA_ENCODED_SIZE} bytes.
187+ *
188+ * Platform is appended separately to the existing platform if it does not exceed {@value MAXIMUM_CLIENT_METADATA_ENCODED_SIZE} bytes.
189+ */
184190 public static BsonDocument updateClientMedataDocument (final BsonDocument clientMetadataDocument ,
185191 final MongoDriverInformation mongoDriverInformation ) {
186- BsonDocument updatedClientMetadataDocument = clientMetadataDocument .clone ();
187192 BsonDocument driverInformation = clientMetadataDocument .getDocument ("driver" );
188193
189194 List <String > driverNamesToAppend = mongoDriverInformation .getDriverNames ();
@@ -203,14 +208,14 @@ public static BsonDocument updateClientMedataDocument(final BsonDocument clientM
203208 updateDriverPlatforms .add (clientMetadataDocument .getString ("platform" ).getValue ());
204209 updateDriverPlatforms .addAll (driverPlatformsToAppend );
205210
206- tryWithLimit (updatedClientMetadataDocument , d -> {
211+ tryWithLimit (clientMetadataDocument , d -> {
207212 putAtPath (d , "driver.name" , listToString (updatedDriverNames ));
208213 putAtPath (d , "driver.version" , listToString (updatedDriverVersions ));
209214 });
210- tryWithLimit (updatedClientMetadataDocument , d -> {
215+ tryWithLimit (clientMetadataDocument , d -> {
211216 putAtPath (d , "platform" , listToString (updateDriverPlatforms ));
212217 });
213- return updatedClientMetadataDocument ;
218+ return clientMetadataDocument ;
214219 }
215220
216221 public enum ContainerRuntime {
0 commit comments