Skip to content

Commit

Permalink
[c#] Do not reuse Protobuf message objects in callbacks, as this cann…
Browse files Browse the repository at this point in the history
…ot reset fields which are not contained on the wire. (#1593) (#1610)
  • Loading branch information
KerstinKeller committed May 28, 2024
1 parent 48683ca commit 0221d4e
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions lang/csharp/Continental/eCAL/Protobuf/ProtoSubscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public ReceiveCallbackData()
}
};

private ReceiveCallbackData receivedData;

/**
* @brief Signature for a data callback.
**/
Expand All @@ -50,7 +48,6 @@ public ProtobufSubscriber(string topicName)
{
T msg = new T();
binarySubscriber = new Subscriber(topicName, Common.ProtobufHelper.GetProtoMessageTypeName(msg), Common.ProtobufHelper.GetProtoMessageDescription(msg));
receivedData = new ReceiveCallbackData();
}

/**
Expand Down Expand Up @@ -83,6 +80,7 @@ private void callBack(String topic, Core.Subscriber.ReceiveCallbackData data)
byte[] messageBytes = Encoding.Default.GetBytes(data.data);
MemoryStream msgStream = new MemoryStream(messageBytes);

var receivedData = new ReceiveCallbackData();
receivedData.data.MergeFrom(msgStream);
receivedData.id = data.id;
receivedData.clock = data.clock;
Expand Down

0 comments on commit 0221d4e

Please sign in to comment.