Skip to content

Commit a94acc3

Browse files
committed
Small fixes
1 parent 8023b9e commit a94acc3

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/MongoDB.Driver/Core/WireProtocol/Messages/Encoders/BinaryEncoders/CommandMessageBinaryEncoder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ namespace MongoDB.Driver.Core.WireProtocol.Messages.Encoders.BinaryEncoders
2828
internal sealed class CommandMessageBinaryEncoder : MessageBinaryEncoderBase, IMessageEncoder
2929
{
3030
private const int EncryptedMaxBatchSize = 2 * 1024 * 1024; // 2 MiB
31-
private readonly ICommandMessageSectionFormatter<Type0CommandMessageSection> _type0SectionFormatter;
31+
private static readonly ICommandMessageSectionFormatter<Type0CommandMessageSection> __type0SectionFormatter = new Type0SectionFormatter(BsonSerializer.DefaultSerializationDomain);
32+
//QUESTION Looking at the spec and our implementation, it seems that type 0 sections always serialize/deserialize RawBsonDocument, so they should use the default domain. Am I missing something?
3233

3334
// constructors
3435
public CommandMessageBinaryEncoder(Stream stream, MessageEncoderSettings encoderSettings)
3536
: base(stream, encoderSettings)
3637
{
37-
_type0SectionFormatter = new Type0SectionFormatter(SerializationDomain);
3838
}
3939

4040
// public methods
@@ -250,7 +250,7 @@ private void WriteSection(BsonBinaryWriter writer, CommandMessageSection section
250250
switch (section)
251251
{
252252
case Type0CommandMessageSection type0Section:
253-
_type0SectionFormatter.FormatSection(type0Section, writer);
253+
__type0SectionFormatter.FormatSection(type0Section, writer);
254254
break;
255255
case Type1CommandMessageSection type1Section:
256256
var type1SectionFormatter = new Type1SectionFormatter(GetSectionMaxSize(), SerializationDomain);

src/MongoDB.Driver/Core/WireProtocol/Messages/Encoders/BinaryEncoders/MessageBinaryEncoderBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ protected int? MaxWireDocumentSize
8383
}
8484

8585
protected IBsonSerializationDomain SerializationDomain
86-
=> _encoderSettings?.GetOrDefault<IBsonSerializationDomain>(MessageEncoderSettingsName.SerializationDomain, null);
86+
=> _encoderSettings?.GetOrDefault<IBsonSerializationDomain>(MessageEncoderSettingsName.SerializationDomain, null) ?? BsonSerializer.DefaultSerializationDomain;
87+
//QUESTION Is this correct? If we don't have a domain in the encoder settings, just use the default one?
8788

8889
// methods
8990
public BsonBinaryReader CreateBinaryReader()

src/MongoDB.Driver/Core/WireProtocol/Messages/Encoders/JsonEncoders/CommandMessageJsonEncoder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ internal sealed class CommandMessageJsonEncoder : MessageJsonEncoderBase, IMessa
3333
public CommandMessageJsonEncoder(TextReader textReader, TextWriter textWriter, MessageEncoderSettings encoderSettings)
3434
: base(textReader, textWriter, encoderSettings)
3535
{
36-
_type0SectionFormatter = new Type0SectionFormatter(SerializationDomain);
36+
//QUESTION Looking at the spec and our implementation, it seems that type 0 sections always serialize/deserialize RawBsonDocument, so they should use the default domain. Am I missing something?
37+
_type0SectionFormatter = new Type0SectionFormatter(BsonSerializer.DefaultSerializationDomain);
3738
_type1SectionFormatter = new Type1SectionFormatter(SerializationDomain);
3839
}
3940

0 commit comments

Comments
 (0)