Skip to content

Commit 6810a93

Browse files
authored
removed CompilerServices.Unsafe dependency (#813)
1 parent b6f41fe commit 6810a93

File tree

4 files changed

+5
-24
lines changed

4 files changed

+5
-24
lines changed

src/Confluent.Kafka/Confluent.Kafka.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
<PackageReference Include="librdkafka.redist" Version="1.0.0-RC7">
2323
<PrivateAssets Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">None</PrivateAssets>
2424
</PackageReference>
25-
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.0" />
2625
<PackageReference Include="System.Memory" Version="4.5.0" />
2726
</ItemGroup>
2827

src/Confluent.Kafka/Consumer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,9 @@ public List<TopicPartitionOffset> Position(IEnumerable<TopicPartition> partition
600600
/// </exception>
601601
public List<TopicPartitionOffset> OffsetsForTimes(IEnumerable<TopicPartitionTimestamp> timestampsToSearch, TimeSpan timeout)
602602
// TODO: use a librdkafka queue for this.
603-
=> kafkaHandle.OffsetsForTimes(timestampsToSearch, timeout.TotalMillisecondsAsInt());
604-
605-
603+
=> kafkaHandle.OffsetsForTimes(timestampsToSearch, timeout.TotalMillisecondsAsInt());
604+
605+
606606
/// <summary>
607607
/// Get the last cached low (oldest available/beginning) and high (newest/end)
608608
/// offsets for a topic/partition. Does not block.
@@ -893,7 +893,7 @@ private ConsumeResult<K, V> ConsumeImpl<K,V>(
893893

894894
try
895895
{
896-
var msg = Util.Marshal.PtrToStructureUnsafe<rd_kafka_message>(msgPtr);
896+
var msg = Util.Marshal.PtrToStructure<rd_kafka_message>(msgPtr);
897897

898898
string topic = null;
899899
if (this.enableTopicNameMarshaling)

src/Confluent.Kafka/Internal/Util.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using System;
1818
using System.Text;
1919
using SystemMarshal = System.Runtime.InteropServices.Marshal;
20-
using Unsafe = System.Runtime.CompilerServices.Unsafe;
2120

2221

2322
namespace Confluent.Kafka.Internal
@@ -50,23 +49,6 @@ public unsafe static string PtrToStringUTF8(IntPtr strPtr)
5049
#endif
5150
}
5251

53-
/// <summary>
54-
/// Reinterpret_cast without strings marshaling
55-
/// </summary>
56-
/// <typeparam name="T">
57-
/// Type of struct to cast
58-
/// </typeparam>
59-
/// <param name="ptr">
60-
/// Raw pointer to use
61-
/// </param>
62-
/// <returns>
63-
/// A value of type <typeparamref name="T"/>
64-
/// </returns>
65-
public static unsafe T PtrToStructureUnsafe<T>(IntPtr ptr)
66-
{
67-
return Unsafe.Read<T>(ptr.ToPointer());
68-
}
69-
7052
public static T PtrToStructure<T>(IntPtr ptr)
7153
{
7254
#if NET45

src/Confluent.Kafka/Producer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private void DeliveryReportCallbackImpl(IntPtr rk, IntPtr rkmessage, IntPtr opaq
133133
// Ensure registered handlers are never called as a side-effect of Dispose/Finalize (prevents deadlocks in common scenarios).
134134
if (ownedKafkaHandle.IsClosed) { return; }
135135

136-
var msg = Util.Marshal.PtrToStructureUnsafe<rd_kafka_message>(rkmessage);
136+
var msg = Util.Marshal.PtrToStructure<rd_kafka_message>(rkmessage);
137137

138138
// the msg._private property has dual purpose. Here, it is an opaque pointer set
139139
// by Topic.Produce to be an IDeliveryHandler. When Consuming, it's for internal

0 commit comments

Comments
 (0)