private void CopyType1Section(BsonStream inputStream, BsonStream outputStream) { var payloadType = (PayloadType)inputStream.ReadByte(); if (payloadType != PayloadType.Type1) { throw new FormatException("Expected subsequent sections to be of type 1."); } var sectionStartPosition = inputStream.Position; var sectionSize = inputStream.ReadInt32(); var sectionEndPosition = sectionStartPosition + sectionSize; var identifier = inputStream.ReadCString(Utf8Encodings.Lenient); outputStream.WriteByte((byte)BsonType.Array); outputStream.WriteCString(identifier); var arrayStartPosition = outputStream.Position; outputStream.WriteInt32(0); // array length will be backpatched var index = 0; while (inputStream.Position < sectionEndPosition) { outputStream.WriteByte((byte)BsonType.Document); outputStream.WriteCString(index.ToString()); CopyBsonDocument(inputStream, outputStream); index++; } outputStream.WriteByte(0); outputStream.BackpatchSize(arrayStartPosition); }
public void BackpatchSize_should_throw_when_stream_is_null() { BsonStream stream = null; Action action = () => stream.BackpatchSize(0); action.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("stream"); }