Skip to content

Commit

Permalink
Merge pull request #68 from thomasjoscht/feature/protobuf-net-v3
Browse files Browse the repository at this point in the history
Compatibility to protobuf-net v3
  • Loading branch information
dotarj authored Feb 18, 2022
2 parents a34d120 + ff9cdb1 commit 06e47eb
Show file tree
Hide file tree
Showing 20 changed files with 142 additions and 135 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto

2 changes: 1 addition & 1 deletion benchmark/protobuf-net-data.Benchmarks/DataReaderMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public bool NextResult()

public bool Read()
{
return ++this.rowIndex < rowCount;
return ++this.rowIndex < this.rowCount;
}

private object GetDefault(Type type)
Expand Down
6 changes: 3 additions & 3 deletions protobuf-net-data.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2005
# Visual Studio Version 17
VisualStudioVersion = 17.0.31919.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "protobuf-net-data", "src\protobuf-net-data\protobuf-net-data.csproj", "{4F6074E7-D9B1-491D-841B-53A752EC1625}"
EndProject
Expand All @@ -27,7 +27,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "protobuf-net-data.Benchmark
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{255B1CD0-4B1F-4601-9176-F36EE56CEF4D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "protobuf-net-data.TestDataGenerator", "tools\protobuf-net-data.TestDataGenerator\protobuf-net-data.TestDataGenerator.csproj", "{4310BE9C-AACD-4071-8675-709E9929138B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "protobuf-net-data.TestDataGenerator", "tools\protobuf-net-data.TestDataGenerator\protobuf-net-data.TestDataGenerator.csproj", "{4310BE9C-AACD-4071-8675-709E9929138B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 1 addition & 1 deletion src/protobuf-net-data/Internal/ColumnsWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private static void WriteColumnName(ProtoWriterContext context, ProtoDataColumn

private static void WriteColumnType(ProtoWriterContext context, ProtoDataColumn column)
{
ProtoWriter.WriteFieldHeader(ColumnTypeFieldHeader, WireType.Variant, context.Writer);
ProtoWriter.WriteFieldHeader(ColumnTypeFieldHeader, WireType.Varint, context.Writer);
ProtoWriter.WriteInt32((int)column.ProtoDataType, context.Writer);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/protobuf-net-data/Internal/ProtoWriterContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Richard Dingwall, Arjen Post. See LICENSE in the project root for license information.

#pragma warning disable CS0618
using System.Collections.Generic;

namespace ProtoBuf.Data.Internal
Expand Down Expand Up @@ -31,3 +32,4 @@ public void EndSubItem()
}
}
}
#pragma warning restore CS0618
12 changes: 6 additions & 6 deletions src/protobuf-net-data/Internal/RecordWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void WriteRecord(ProtoWriterContext context, int recordIndex, IDat
break;

case ProtoDataType.Short:
ProtoWriter.WriteFieldHeader(fieldNumber, WireType.Variant, context.Writer);
ProtoWriter.WriteFieldHeader(fieldNumber, WireType.Varint, context.Writer);
ProtoWriter.WriteInt16(record.GetInt16(columnIndex), context.Writer);
break;

Expand All @@ -46,7 +46,7 @@ public static void WriteRecord(ProtoWriterContext context, int recordIndex, IDat
break;

case ProtoDataType.Int:
ProtoWriter.WriteFieldHeader(fieldNumber, WireType.Variant, context.Writer);
ProtoWriter.WriteFieldHeader(fieldNumber, WireType.Varint, context.Writer);
ProtoWriter.WriteInt32(record.GetInt32(columnIndex), context.Writer);
break;

Expand All @@ -61,17 +61,17 @@ public static void WriteRecord(ProtoWriterContext context, int recordIndex, IDat
break;

case ProtoDataType.Bool:
ProtoWriter.WriteFieldHeader(fieldNumber, WireType.Variant, context.Writer);
ProtoWriter.WriteFieldHeader(fieldNumber, WireType.Varint, context.Writer);
ProtoWriter.WriteBoolean(record.GetBoolean(columnIndex), context.Writer);
break;

case ProtoDataType.Byte:
ProtoWriter.WriteFieldHeader(fieldNumber, WireType.Variant, context.Writer);
ProtoWriter.WriteFieldHeader(fieldNumber, WireType.Varint, context.Writer);
ProtoWriter.WriteByte(record.GetByte(columnIndex), context.Writer);
break;

case ProtoDataType.Char:
ProtoWriter.WriteFieldHeader(fieldNumber, WireType.Variant, context.Writer);
ProtoWriter.WriteFieldHeader(fieldNumber, WireType.Varint, context.Writer);
ProtoWriter.WriteInt16((short)record.GetChar(columnIndex), context.Writer);
break;

Expand All @@ -86,7 +86,7 @@ public static void WriteRecord(ProtoWriterContext context, int recordIndex, IDat
break;

case ProtoDataType.Long:
ProtoWriter.WriteFieldHeader(fieldNumber, WireType.Variant, context.Writer);
ProtoWriter.WriteFieldHeader(fieldNumber, WireType.Varint, context.Writer);
ProtoWriter.WriteInt64(record.GetInt64(columnIndex), context.Writer);
break;

Expand Down
50 changes: 26 additions & 24 deletions src/protobuf-net-data/ProtoDataReader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Richard Dingwall, Arjen Post. See LICENSE in the project root for license information.

#pragma warning disable CS0618
using System;
using System.Collections.Generic;
using System.Data;
Expand Down Expand Up @@ -35,7 +36,7 @@ public ProtoDataReader(Stream stream)
}

this.stream = stream;
this.reader = new ProtoReader(stream, null, null);
this.reader = ProtoReader.Create(stream, null, null);
this.context = new ProtoReaderContext(this.reader);

ResultReader.ReadResult(this.context);
Expand Down Expand Up @@ -606,41 +607,41 @@ private void Dispose(bool disposing)
{
// via case sensitive search, first match with lowest ordinal matches
var ordinal = this.GetColumnOrdinalByName(name, CompareOptions.None);
if (ordinal.HasValue)
{
return ordinal;
if (ordinal.HasValue)
{
return ordinal;
}

// via case insensitive search, first match with lowest ordinal matches
ordinal = this.GetColumnOrdinalByName(name, CompareOptions.IgnoreCase);
if (ordinal.HasValue)
{
return ordinal;
}

// do the slow search now (kana, width insensitive comparison)
var compareOptions = CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase;
ordinal = this.GetColumnOrdinalByName(name, CompareOptions.IgnoreCase);
if (ordinal.HasValue)
{
return ordinal;
}

// do the slow search now (kana, width insensitive comparison)
var compareOptions = CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase;
ordinal = this.GetColumnOrdinalByName(name, compareOptions);
if (ordinal.HasValue)
{
return ordinal;
}

if (ordinal.HasValue)
{
return ordinal;
}

return null;
}

private int? GetColumnOrdinalByName(string name, CompareOptions compareOptions)
{
var compareInfo = CultureInfo.InvariantCulture.CompareInfo;
private int? GetColumnOrdinalByName(string name, CompareOptions compareOptions)
{
var compareInfo = CultureInfo.InvariantCulture.CompareInfo;
for (var ordinal = 0; ordinal < this.context.Columns.Count; ordinal++)
{
if (compareInfo.Compare(name, this.context.Columns[ordinal].Name, compareOptions) == 0)
{
return ordinal;
}
}

return null;
}

return null;
}

private DataTable BuildSchemaTable()
Expand Down Expand Up @@ -775,4 +776,5 @@ private void ThrowIfNoData()
}
}
}
}
}
#pragma warning restore CS0618
6 changes: 4 additions & 2 deletions src/protobuf-net-data/ProtoDataStream.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Richard Dingwall, Arjen Post. See LICENSE in the project root for license information.

#pragma warning disable CS0618
using System;
using System.Collections.Generic;
using System.Data;
Expand Down Expand Up @@ -134,7 +135,7 @@ public ProtoDataStream(

this.resultIndex = 0;
this.bufferStream = new CircularStream(bufferSize);
this.writer = new ProtoWriter(this.bufferStream, null, null);
this.writer = ProtoWriter.Create(this.bufferStream, null, null);
this.context = new ProtoWriterContext(this.writer, this.options);
}

Expand Down Expand Up @@ -368,4 +369,5 @@ private void FillBuffer(int requestedLength)
}
}
}
}
}
#pragma warning restore CS0618
9 changes: 7 additions & 2 deletions src/protobuf-net-data/ProtoDataWriter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Richard Dingwall, Arjen Post. See LICENSE in the project root for license information.

#pragma warning disable CS0618
using System.Data;
using System.IO;
using ProtoBuf.Data.Internal;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void Serialize(Stream stream, IDataReader reader, ProtoDataWriterOptions

var resultIndex = 0;

using (var writer = new ProtoWriter(stream, null, null))
using (var writer = ProtoWriter.Create(stream, null, null))
{
var context = new ProtoWriterContext(writer, options);

Expand Down Expand Up @@ -106,7 +107,11 @@ public void Serialize(Stream stream, IDataReader reader, ProtoDataWriterOptions
resultIndex++;
}
while (reader.NextResult());

// necessary since protobuf-net v3
writer.Close();
}
}
}
}
}
#pragma warning restore CS0618
6 changes: 3 additions & 3 deletions src/protobuf-net-data/protobuf-net-data.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<DebugSymbols>true</DebugSymbols>
<DebugType Condition="$(codecov) == 'true'">full</DebugType>
<DebugType Condition="$(codecov) != 'true'">embedded</DebugType>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IncludeSymbols>false</IncludeSymbols>
<TargetFrameworks>net20;net30;net35;net40;net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>0.0.0</Version>
</PropertyGroup>
Expand All @@ -30,7 +30,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="protobuf-net" Version="2.3.2" />
<PackageReference Include="protobuf-net" Version="3.0.101" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Richard Dingwall, Arjen Post. See LICENSE in the project root for license information.

#pragma warning disable CS0618
using System;
using System.Collections.Generic;
using System.Data;
Expand All @@ -12,34 +13,13 @@ public partial class ColumnsReaderTests
{
public class TheReadColumnsMethod : ColumnsReaderTests
{
[Fact]
public void ShouldThrowExceptionOnColumnsInvalidFieldHeader()
{
// Arrange
var stream = new MemoryStream();

using (var writer = new ProtoWriter(stream, null, null))
{
ProtoWriter.WriteFieldHeader(1, WireType.StartGroup, writer);

ProtoWriter.StartSubItem(0, writer);

ProtoWriter.WriteFieldHeader(42, WireType.StartGroup, writer);
}

stream.Position = 0;

// Assert
Assert.Throws<InvalidDataException>(() => new ProtoDataReader(stream));
}

[Fact]
public void ShouldThrowExceptionOnColumnNameInvalidFieldHeader()
{
// Arrange
var stream = new MemoryStream();

using (var writer = new ProtoWriter(stream, null, null))
using (var writer = ProtoWriter.Create(stream, null, null))
{
ProtoWriter.WriteFieldHeader(1, WireType.StartGroup, writer);

Expand All @@ -55,6 +35,8 @@ public void ShouldThrowExceptionOnColumnNameInvalidFieldHeader()
ProtoWriter.EndSubItem(columnToken, writer);

ProtoWriter.EndSubItem(resultToken, writer);

writer.Close();
}

stream.Position = 0;
Expand All @@ -69,7 +51,7 @@ public void ShouldThrowExceptionOnColumnTypeInvalidFieldHeader()
// Arrange
var stream = new MemoryStream();

using (var writer = new ProtoWriter(stream, null, null))
using (var writer = ProtoWriter.Create(stream, null, null))
{
ProtoWriter.WriteFieldHeader(1, WireType.StartGroup, writer);

Expand All @@ -81,12 +63,14 @@ public void ShouldThrowExceptionOnColumnTypeInvalidFieldHeader()

ProtoWriter.WriteFieldHeader(1, WireType.String, writer);
ProtoWriter.WriteString("foo", writer);
ProtoWriter.WriteFieldHeader(42, WireType.Variant, writer);
ProtoWriter.WriteFieldHeader(42, WireType.Varint, writer);
ProtoWriter.WriteInt32((int)1, writer);

ProtoWriter.EndSubItem(columnToken, writer);

ProtoWriter.EndSubItem(resultToken, writer);

writer.Close();
}

stream.Position = 0;
Expand All @@ -101,7 +85,7 @@ public void ShouldAcceptTrailingFieldHeaders()
// Arrange
var stream = new MemoryStream();

using (var writer = new ProtoWriter(stream, null, null))
using (var writer = ProtoWriter.Create(stream, null, null))
{
ProtoWriter.WriteFieldHeader(1, WireType.StartGroup, writer);

Expand All @@ -113,14 +97,16 @@ public void ShouldAcceptTrailingFieldHeaders()

ProtoWriter.WriteFieldHeader(1, WireType.String, writer);
ProtoWriter.WriteString("foo", writer);
ProtoWriter.WriteFieldHeader(2, WireType.Variant, writer);
ProtoWriter.WriteFieldHeader(2, WireType.Varint, writer);
ProtoWriter.WriteInt32((int)1, writer);
ProtoWriter.WriteFieldHeader(42, WireType.String, writer);
ProtoWriter.WriteString("bar", writer);

ProtoWriter.EndSubItem(columnToken, writer);

ProtoWriter.EndSubItem(resultToken, writer);

writer.Close();
}

stream.Position = 0;
Expand All @@ -131,3 +117,4 @@ public void ShouldAcceptTrailingFieldHeaders()
}
}
}
#pragma warning restore CS0618
Loading

0 comments on commit 06e47eb

Please sign in to comment.