Skip to content
This repository has been archived by the owner on Feb 22, 2025. It is now read-only.

Commit

Permalink
Upstream pull (#771)
Browse files Browse the repository at this point in the history
* Update `MessagePack` to 1.9.11 (#4078)

* Manual upgrade to 1.9.11

* Fix Tests

* Extension class

* Changes

* Add extensions.

* Add extensions tests

* snapshot files update

---------

Co-authored-by: Tony Redondo <tony.redondo@datadoghq.com>
  • Loading branch information
lachmatt and tonyredondo authored Feb 15, 2024
1 parent 068ca11 commit 71c5b49
Show file tree
Hide file tree
Showing 90 changed files with 8,161 additions and 84 deletions.
42 changes: 39 additions & 3 deletions tracer/build/_build/UpdateVendors/VendoredDependency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ static VendoredDependency()

Add(
libraryName: "MessagePack",
version: "1.9.3",
downloadUrl: "https://github.com/neuecc/MessagePack-CSharp/archive/v1.9.3.zip",
pathToSrc: new[] { "MessagePack-CSharp-1.9.3", "src", "MessagePack" },
version: "1.9.11",
downloadUrl: "https://github.com/neuecc/MessagePack-CSharp/archive/refs/tags/v1.9.11.zip",
pathToSrc: new[] { "MessagePack-CSharp-1.9.11", "src", "MessagePack" },
transform: filePath => RewriteCsFileWithStandardTransform(filePath, originalNamespace: "MessagePack"));

Add(
Expand Down Expand Up @@ -223,6 +223,42 @@ private bool TryGetValue(string key, [NotNullWhen(true)]out JsonProperty? item)
builder.Replace("\"ProtoBuf.ProtoIgnoreAttribute\"", "\"Datadog.Trace.Vendors.ProtoBuf.ProtoIgnoreAttribute\"");
builder.Replace("\"ProtoBuf.ProtoMemberAttribute\"", "\"Datadog.Trace.Vendors.ProtoBuf.ProtoMemberAttribute\"");
}
// Special MessagePack processing
if (originalNamespace.StartsWith("MessagePack"))
{
var fileName = Path.GetFileNameWithoutExtension(filePath);
if (fileName == "StandardClassLibraryFormatter")
{
builder.Replace(" public sealed class ValueTaskFormatter<T>", "#if NETCOREAPP\n public sealed class ValueTaskFormatter<T>");
builder.Replace(" }\n\n#endif\n}", " }\n#endif\n\n#endif\n}");
}
else if (fileName == "ValueTupleFormatter")
{
builder.Replace("#if NETSTANDARD || NETFRAMEWORK", "#if NETSTANDARD || NETCOREAPP");
}
else if (fileName == "DynamicAssembly")
{
builder.Replace("#if NETSTANDARD || NETFRAMEWORK", "#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP");
}
else if (fileName == "LZ4Codec.Helper")
{
builder.Replace("#if NETSTANDARD || NETFRAMEWORK", "#if ENABLE_UNSAFE_MSGPACK");
}
else if (fileName == "StandardResolver")
{
builder.Replace("#if !(NETSTANDARD || NETFRAMEWORK)", "#if !(NETSTANDARD || NETFRAMEWORK || NETCOREAPP)");
}
else if (fileName == "DynamicGenericResolver")
{
builder.Replace(" // ValueTask", "#if NETCOREAPP\n // ValueTask");
builder.Replace(" // ValueTuple", "#if NETCOREAPP\n // ValueTuple");
builder.Replace(" // Tuple", "#endif\n // Tuple");
builder.Replace(" // ArraySegement", "#endif\n // ArraySegment");
builder.Replace("GetTypeInfo().IsConstructedGenericType()", "IsConstructedGenericType");
}

builder.Replace("#if NETSTANDARD || NETFRAMEWORK\n [System.Runtime.CompilerServices.MethodImpl", "#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP\n [System.Runtime.CompilerServices.MethodImpl");
}

// Debugger.Break() is a dangerous method that may crash the process. We don't
// want to take any risk of calling it, ever, so replace it with a noop.
Expand Down
4 changes: 2 additions & 2 deletions tracer/dependabot/Datadog.Dependabot.Vendors.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<!-- https://www.nuget.org/packages/StatsdClient/6.0.0 -->
<PackageReference Include="StatsdClient" Version="6.0.0" />

<!-- https://www.nuget.org/packages/MessagePack/1.9.3 -->
<PackageReference Include="MessagePack" Version="1.9.3" />
<!-- https://www.nuget.org/packages/MessagePack/1.9.11 -->
<PackageReference Include="MessagePack" Version="1.9.11" />

<!-- https://www.nuget.org/packages/Newtonsoft.Json/13.0.1 -->
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// <copyright file="MessagePackBinaryExtensions.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

#if NETCOREAPP
using System;

namespace Datadog.Trace.Vendors.MessagePack
{
internal static partial class MessagePackBinary
{
public static int WriteRaw(ref byte[] bytes, int offset, ReadOnlySpan<byte> rawMessagePackBlock)
{
EnsureCapacity(ref bytes, offset, rawMessagePackBlock.Length);
rawMessagePackBlock.CopyTo(bytes.AsSpan(offset, rawMessagePackBlock.Length));
return rawMessagePackBlock.Length;
}

public static int WriteBytes(ref byte[] bytes, int offset, ReadOnlySpan<byte> rawMessagePackBlock)
{
var count = rawMessagePackBlock.Length;
if (count <= byte.MaxValue)
{
var size = count + 2;
EnsureCapacity(ref bytes, offset, size);

bytes[offset] = MessagePackCode.Bin8;
bytes[offset + 1] = (byte)count;

rawMessagePackBlock.CopyTo(bytes.AsSpan(offset + 2, count));
return size;
}
else if (count <= ushort.MaxValue)
{
var size = count + 3;
EnsureCapacity(ref bytes, offset, size);

unchecked
{
bytes[offset] = MessagePackCode.Bin16;
bytes[offset + 1] = (byte)(count >> 8);
bytes[offset + 2] = (byte)(count);
}

rawMessagePackBlock.CopyTo(bytes.AsSpan(offset + 3, count));
return size;
}
else
{
var size = count + 5;
EnsureCapacity(ref bytes, offset, size);

unchecked
{
bytes[offset] = MessagePackCode.Bin32;
bytes[offset + 1] = (byte)(count >> 24);
bytes[offset + 2] = (byte)(count >> 16);
bytes[offset + 3] = (byte)(count >> 8);
bytes[offset + 4] = (byte)(count);
}

rawMessagePackBlock.CopyTo(bytes.AsSpan(offset + 5, count));
return size;
}
}

public static int WriteStringBytes(ref byte[] bytes, int offset, ReadOnlySpan<byte> utf8stringBytes)
{
var byteCount = utf8stringBytes.Length;
if (byteCount <= MessagePackRange.MaxFixStringLength)
{
EnsureCapacity(ref bytes, offset, byteCount + 1);
bytes[offset] = (byte)(MessagePackCode.MinFixStr | byteCount);
utf8stringBytes.CopyTo(bytes.AsSpan(offset + 1, byteCount));
return byteCount + 1;
}
else if (byteCount <= byte.MaxValue)
{
EnsureCapacity(ref bytes, offset, byteCount + 2);
bytes[offset] = MessagePackCode.Str8;
bytes[offset + 1] = unchecked((byte)byteCount);
utf8stringBytes.CopyTo(bytes.AsSpan(offset + 2, byteCount));
return byteCount + 2;
}
else if (byteCount <= ushort.MaxValue)
{
EnsureCapacity(ref bytes, offset, byteCount + 3);
bytes[offset] = MessagePackCode.Str16;
bytes[offset + 1] = unchecked((byte)(byteCount >> 8));
bytes[offset + 2] = unchecked((byte)byteCount);
utf8stringBytes.CopyTo(bytes.AsSpan(offset + 3, byteCount));
return byteCount + 3;
}
else
{
EnsureCapacity(ref bytes, offset, byteCount + 5);
bytes[offset] = MessagePackCode.Str32;
bytes[offset + 1] = unchecked((byte)(byteCount >> 24));
bytes[offset + 2] = unchecked((byte)(byteCount >> 16));
bytes[offset + 3] = unchecked((byte)(byteCount >> 8));
bytes[offset + 4] = unchecked((byte)byteCount);
utf8stringBytes.CopyTo(bytes.AsSpan(offset + 5, byteCount));
return byteCount + 5;
}
}
}
}
#endif
1 change: 1 addition & 0 deletions tracer/src/Datadog.Trace/Vendors/MessagePack/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032
using System;

namespace Datadog.Trace.Vendors.MessagePack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
Expand Down
1 change: 1 addition & 0 deletions tracer/src/Datadog.Trace/Vendors/MessagePack/FloatBits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032
using System;
using System.Runtime.InteropServices;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP
#if NETSTANDARD || NETFRAMEWORK
using System.Collections.Concurrent;
#endif

Expand Down Expand Up @@ -247,7 +248,7 @@ public int Serialize(ref byte[] bytes, int offset, TCollection value, IFormatter
{
while (e.MoveNext())
{
#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP
#if NETSTANDARD || NETFRAMEWORK
offset += formatter.Serialize(ref bytes, offset, e.Current, formatterResolver);
#else
offset += formatter.Serialize(ref bytes, (int)offset, (TElement)e.Current, (IFormatterResolver)formatterResolver);
Expand Down Expand Up @@ -278,7 +279,7 @@ public int Serialize(ref byte[] bytes, int offset, TCollection value, IFormatter
while (e.MoveNext())
{
count++;
#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP
#if NETSTANDARD || NETFRAMEWORK
var writeSize = formatter.Serialize(ref bytes, offset, e.Current, formatterResolver);
#else
var writeSize = formatter.Serialize(ref bytes, (int)offset, (TElement)e.Current, (IFormatterResolver)formatterResolver);
Expand Down Expand Up @@ -348,7 +349,7 @@ public TCollection Deserialize(byte[] bytes, int offset, IFormatterResolver form
{
return collection.Count;
}
#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP
#if NETSTANDARD || NETFRAMEWORK
else
{
var c2 = sequence as IReadOnlyCollection<TElement>;
Expand Down Expand Up @@ -952,7 +953,7 @@ public IDictionary Deserialize(byte[] bytes, int offset, IFormatterResolver form
}
}

#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP
#if NETSTANDARD || NETFRAMEWORK

internal sealed class ObservableCollectionFormatter<T> : CollectionFormatterBase<T, ObservableCollection<T>>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP
#if NETSTANDARD || NETFRAMEWORK
using System.Collections.Concurrent;
#endif

namespace Datadog.Trace.Vendors.MessagePack.Formatters
{
#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP
#if NETSTANDARD || NETFRAMEWORK

// unfortunately, can't use IDictionary<KVP> because supports IReadOnlyDictionary.
internal abstract class DictionaryFormatterBase<TKey, TValue, TIntermediate, TEnumerator, TDictionary> : IMessagePackFormatter<TDictionary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032
#if NETSTANDARD || NETFRAMEWORK

using Datadog.Trace.Vendors.MessagePack.Resolvers;
using System;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032
using System;
using System.Collections.Generic;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032
using System;

namespace Datadog.Trace.Vendors.MessagePack.Formatters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032

namespace Datadog.Trace.Vendors.MessagePack.Formatters
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032
namespace Datadog.Trace.Vendors.MessagePack.Formatters
{
internal sealed class IgnoreFormatter<T> : IMessagePackFormatter<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032
using System;
using System.Collections.Generic;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032
using System;
using System.Collections.Generic;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032
using System;

namespace Datadog.Trace.Vendors.MessagePack.Formatters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032
using System;

namespace Datadog.Trace.Vendors.MessagePack.Formatters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// <auto-generated />
// This file was automatically generated by the UpdateVendors tool.
//------------------------------------------------------------------------------
#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032
using System;
using System.Reflection;
using System.Collections.Generic;
Expand Down
Loading

0 comments on commit 71c5b49

Please sign in to comment.