Skip to content
This repository was archived by the owner on Jun 26, 2024. It is now read-only.

Commit b2be0e1

Browse files
Initial commit to demonstrate method
1 parent 5946840 commit b2be0e1

File tree

7 files changed

+24
-4
lines changed

7 files changed

+24
-4
lines changed

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "2.1.500"
3+
"version": "2.1.818"
44
},
55
"msbuild-sdks": {
66
"MSBuild.Sdk.Extras": "1.5.4",

src/protobuf-net.Test/protobuf-net.Test.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<PropertyGroup>
44
<GenerateDocumentationFile>false</GenerateDocumentationFile>
55
<!--<TargetFrameworks>netcoreapp1.1;net452</TargetFrameworks>-->
6-
<TargetFrameworks>net452</TargetFrameworks>
6+
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
77
<LibImport>net</LibImport>
88
<Configurations>Debug;Release;VS</Configurations>
99
</PropertyGroup>
10-
<PropertyGroup Condition="$(TargetFramework)=='netcoreapp1.1'">
10+
<PropertyGroup Condition="$(TargetFramework)=='netcoreapp2.1'">
1111
<DefineConstants>FEAT_COMPILER;NO_NHIBERNATE;COREFX;NO_INTERNAL_CONTEXT</DefineConstants>
1212
<LibImport>core</LibImport>
1313
</PropertyGroup>

src/protobuf-net/ProtoReader.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public sealed class ProtoReader : IDisposable
3333
/// </summary>
3434
public int FieldNumber => fieldNumber;
3535

36+
/// <summary>
37+
/// Returns true if the field being processed is an empty list.
38+
/// </summary>
39+
public bool IsEmptyList => (fieldNumber & Serializer.EmptyListFlag) == Serializer.EmptyListFlag;
40+
3641
/// <summary>
3742
/// Indicates the underlying proto serialization format on the wire.
3843
/// </summary>

src/protobuf-net/Serializer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ namespace ProtoBuf
1818
/// </remarks>
1919
public static class Serializer
2020
{
21+
public const int EmptyListFlag = 0x01000000;
22+
2123
#if !NO_RUNTIME
2224
/// <summary>
2325
/// Suggest a .proto definition for the given type

src/protobuf-net/Serializers/ListDecorator.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,12 @@ public override void Write(object value, ProtoWriter dest)
494494
token = new SubItemToken(); // default
495495
}
496496
bool checkForNull = !SupportNull;
497+
bool isEmpty = true;
497498
foreach (object subItem in (IEnumerable)value)
498499
{
499500
if (checkForNull && subItem == null) { throw new NullReferenceException(); }
500501
Tail.Write(subItem, dest);
502+
isEmpty = false;
501503
}
502504
if (writePacked)
503505
{
@@ -510,6 +512,11 @@ public override void Write(object value, ProtoWriter dest)
510512
ProtoWriter.EndSubItem(token, dest);
511513
}
512514
}
515+
else if (isEmpty)
516+
{
517+
ProtoWriter.WriteFieldHeader(fieldNumber | Serializer.EmptyListFlag, WireType.String, dest);
518+
ProtoWriter.WriteString("", dest);
519+
}
513520
}
514521

515522
private bool CanUsePackedPrefix(object obj) =>
@@ -522,6 +529,11 @@ public override object Read(object value, ProtoReader source)
522529
int field = source.FieldNumber;
523530
object origValue = value;
524531
if (value == null) value = Activator.CreateInstance(concreteType);
532+
if (source.IsEmptyList)
533+
{
534+
return value;
535+
}
536+
525537
bool isList = IsList && !SuppressIList;
526538
if (packedWireType != WireType.None && source.WireType == WireType.String)
527539
{

src/protobuf-net/Serializers/TypeSerializer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public object Read(object value, ProtoReader source)
198198
}
199199
for (int i = lastFieldIndex; i < fieldNumbers.Length; i++)
200200
{
201+
fieldNumber &= ~Serializer.EmptyListFlag;
201202
if (fieldNumbers[i] == fieldNumber)
202203
{
203204
IProtoSerializer ser = serializers[i];

src/protobuf-net/protobuf-net.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<AssemblyName>protobuf-net</AssemblyName>
44
<Title>protobuf-net</Title>
55
<Description>Provides simple access to fast and efficient "Protocol Buffers" serialization from .NET applications</Description>
6-
<TargetFrameworks>net35;net451;netstandard2.0;netcoreapp2.1</TargetFrameworks>
6+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<DefineConstants>EMIT_ASSEMBLY_INFO</DefineConstants>
99
<!-- new build tools spit these out -->

0 commit comments

Comments
 (0)