Skip to content

Commit f750055

Browse files
Do not calculate statistics json length as it is already provided by librdkafka (#1825)
1 parent 3cd6776 commit f750055

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Confluent.Kafka/Consumer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private int StatisticsCallback(IntPtr rk, IntPtr json, UIntPtr json_len, IntPtr
112112
try
113113
{
114114
// Ensure registered handlers are never called as a side-effect of Dispose/Finalize (prevents deadlocks in common scenarios).
115-
statisticsHandler?.Invoke(Util.Marshal.PtrToStringUTF8(json));
115+
statisticsHandler?.Invoke(Util.Marshal.PtrToStringUTF8(json, json_len));
116116
}
117117
catch (Exception e)
118118
{

src/Confluent.Kafka/Internal/Util.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public unsafe static string PtrToStringUTF8(IntPtr strPtr)
6969
return Encoding.UTF8.GetString((byte*)strPtr.ToPointer(), length);
7070
}
7171

72+
public unsafe static string PtrToStringUTF8(IntPtr strPtr, UIntPtr strLength)
73+
{
74+
if (strPtr == IntPtr.Zero)
75+
{
76+
return null;
77+
}
78+
79+
return Encoding.UTF8.GetString((byte*)strPtr.ToPointer(), (int)strLength);
80+
}
81+
7282
public static T PtrToStructure<T>(IntPtr ptr)
7383
{
7484
return SystemMarshal.PtrToStructure<T>(ptr);

0 commit comments

Comments
 (0)