Ejemplo n.º 1
0
        public void Write(BridgeType message, Action completed)
        {
            int topicLength   = Topic.Length;
            int messageLength = Ros2Serialization.GetLength(message);

            var bytes = new byte[1 + 4 + topicLength + 4 + messageLength];

            bytes[0] = (byte)BridgeOp.Publish;

            bytes[1] = (byte)(topicLength >> 0);
            bytes[2] = (byte)(topicLength >> 8);
            bytes[3] = (byte)(topicLength >> 16);
            bytes[4] = (byte)(topicLength >> 24);
            Buffer.BlockCopy(Topic, 0, bytes, 5, topicLength);

            bytes[5 + topicLength] = (byte)(messageLength >> 0);
            bytes[6 + topicLength] = (byte)(messageLength >> 8);
            bytes[7 + topicLength] = (byte)(messageLength >> 16);
            bytes[8 + topicLength] = (byte)(messageLength >> 24);
            int written = Ros2Serialization.Serialize(message, bytes, 9 + topicLength);

            Debug.Assert(written == messageLength, "Something is terribly wrong if this is not true");

            Instance.SendAsync(bytes, completed);
        }
Ejemplo n.º 2
0
 public void RegSubscriber <DataType, BridgeType>(IBridgePlugin plugin, Func <BridgeType, DataType> converter)
 {
     plugin.AddType <DataType>(Ros2Utils.GetMessageType <BridgeType>());
     plugin.AddSubscriberCreator <DataType>(
         (instance, topic, callback) => (instance as Ros2BridgeInstance).AddSubscriber <BridgeType>(topic,
                                                                                                    rawData => callback(converter(Ros2Serialization.Unserialize <BridgeType>(rawData)))
                                                                                                    )
         );
 }