Exemple #1
0
 public CustomType(Type type, byte bSign, SerializeFunc serializeFunc, DeserializeFunc deserializeFunc)
 {
     this.type            = type;
     this.bSign           = bSign;
     this.serializeFunc   = serializeFunc;
     this.deserializeFunc = deserializeFunc;
 }
        private void CheckSerializers <T>(
            T value,
            T expectedDeserializeValue,
            int expectedSerializeSize,
            int?reportedSerializeSize,
            CalculateSizeFunc <T> calculateSizeFunc,
            SerializeFunc <T> serializeFunc,
            DeserializeFunc <T> deserializeFunc
            ) where
        T : struct
        {
            if (reportedSerializeSize != null)
            {
                Assert.Equal(expectedSerializeSize, reportedSerializeSize);
            }

            Assert.Equal(expectedSerializeSize, calculateSizeFunc(value));

            byte[]      output1    = new byte[expectedSerializeSize];
            Span <byte> outputItr1 = BitSerializer.Serialize(output1, value);

            Assert.Equal(0, outputItr1.Length);

            byte[]      output2    = new byte[expectedSerializeSize];
            Span <byte> outputItr2 = BitSerializer <T> .Serialize(output2, value);

            Assert.Equal(0, outputItr2.Length);

            byte[]      output3    = new byte[expectedSerializeSize];
            Span <byte> outputItr3 = serializeFunc(output3, value);

            Assert.Equal(0, outputItr3.Length);

            Assert.Equal(output1, output2);
            Assert.Equal(output1, output3);

            T value1;
            ReadOnlySpan <byte> inputItr1 = BitSerializer.Deserialize(output1, out value1);

            Assert.Equal(0, inputItr1.Length);

            T value2;
            ReadOnlySpan <byte> inputItr2 = BitSerializer <T> .Deserialize(output2, out value2);

            Assert.Equal(0, inputItr2.Length);

            T value3;
            ReadOnlySpan <byte> inputItr3 = deserializeFunc(output3, out value3);

            Assert.Equal(0, inputItr3.Length);

            expectedDeserializeValue.ShouldCompare(value1);
            expectedDeserializeValue.ShouldCompare(value2);
            expectedDeserializeValue.ShouldCompare(value3);
        }
Exemple #3
0
        public void publish(string topic, SerializeFunc serfunc, IRosMessage msg)
        {
            if (msg == null)
            {
                return;
            }
            lock (advertised_topics_mutex)
            {
                Publication p;
                if ((p = lookupPublicationWithoutLock(topic)) == null || !ROS.ok || shutting_down)
                {
                    return;
                }
                p.connection_header = new Header {
                    Values = new Hashtable()
                };
                p.connection_header.Values["type"]               = p.DataType;
                p.connection_header.Values["md5sum"]             = p.Md5sum;
                p.connection_header.Values["message_definition"] = p.MessageDefinition;
                p.connection_header.Values["callerid"]           = this_node.Name;
                p.connection_header.Values["latching"]           = p.Latch;

                if (p == null)
                {
                    return;
                }
                if (p.HasSubscribers || p.Latch)
                {
                    bool nocopy    = false;
                    bool serialize = false;
                    if (msg != null && msg.msgtype != MsgTypes.Unknown)
                    {
                        p.getPublishTypes(ref serialize, ref nocopy, ref msg.msgtype);
                    }
                    else
                    {
                        serialize = true;
                    }
                    msg.Serialized = serfunc();


                    p.publish(msg);

                    if (serialize)
                    {
                        PollManager.Instance.poll_set.signal();
                    }
                }
                else
                {
                    p.incrementSequence();
                }
            }
        }
 private void CheckSerializers <T>(
     T value,
     int expectedSerializeSize,
     int?reportedSerializeSize,
     CalculateSizeFunc <T> calculateSizeFunc,
     SerializeFunc <T> serializeFunc,
     DeserializeFunc <T> deserializeFunc
     ) where
 T : struct
 {
     CheckSerializers(value, value, expectedSerializeSize, reportedSerializeSize, calculateSizeFunc, serializeFunc, deserializeFunc);
 }
Exemple #5
0
        public void publish(Publication p, RosMessage msg, SerializeFunc serfunc = null)
        {
            if (msg == null)
            {
                return;
            }
            if (serfunc == null)
            {
                serfunc = msg.Serialize;
            }
            if (p.connection_header == null)
            {
                p.connection_header = new Header {
                    Values = new Dictionary <string, string>()
                };
                p.connection_header.Values["type"]               = p.DataType;
                p.connection_header.Values["md5sum"]             = p.Md5sum;
                p.connection_header.Values["message_definition"] = p.MessageDefinition;
                p.connection_header.Values["callerid"]           = ThisNode.Name;
                p.connection_header.Values["latching"]           = Convert.ToString(p.Latch);
            }

            if (!ROS.ok || shuttingDown)
            {
                return;
            }

            if (p.HasSubscribers || p.Latch)
            {
                bool nocopy    = false;
                bool serialize = false;
                if (msg != null && msg.MessageType != "undefined/unknown")
                {
                    p.getPublishTypes(ref serialize, ref nocopy, msg.MessageType);
                }
                else
                {
                    serialize = true;
                }

                p.publish(new MessageAndSerializerFunc(msg, serfunc, serialize, nocopy));

                if (serialize)
                {
                    PollManager.Instance.poll_set.ContinueThreads();
                }
            }
            else
            {
                p.incrementSequence();
            }
        }
        public void publish(Publication p, IRosMessage msg, SerializeFunc serfunc = null)
        {
            if (msg == null)
            {
                return;
            }
            if (serfunc == null)
            {
                serfunc = msg.Serialize;
            }
            if (p.connection_header == null)
            {
                p.connection_header = new Header {
                    Values = new Hashtable()
                };
                p.connection_header.Values["type"]               = p.DataType;
                p.connection_header.Values["md5sum"]             = p.Md5sum;
                p.connection_header.Values["message_definition"] = p.MessageDefinition;
                p.connection_header.Values["callerid"]           = this_node.Name;
                p.connection_header.Values["latching"]           = p.Latch;
            }
            if (!ROS.ok || shutting_down)
            {
                return;
            }
            if (p.HasSubscribers || p.Latch)
            {
                bool nocopy    = false;
                bool serialize = false;
                if (msg != null && msg.msgtype() != MsgTypes.Unknown)
                {
                    p.getPublishTypes(ref serialize, ref nocopy, msg.msgtype());
                }
                else
                {
                    serialize = true;
                }

                p.publish(new MessageAndSerializerFunc(msg, serfunc, serialize, nocopy));

                if (serialize)
                {
                    PollManager.Instance.poll_set.signal();
                }
            }
            else
            {
                p.incrementSequence();
            }
        }
Exemple #7
0
        public void Publish(Publication p, RosMessage msg, SerializeFunc serfunc = null)
        {
            if (msg == null)
            {
                return;
            }

            if (serfunc == null)
            {
                serfunc = msg.Serialize;
            }

            if (p.connectionHeader == null)
            {
                var fields = new Dictionary <string, string>()
                {
                    ["type"]               = p.DataType,
                    ["md5sum"]             = p.Md5Sum,
                    ["message_definition"] = p.MessageDefinition,
                    ["callerid"]           = ThisNode.Name,
                    ["latching"]           = p.Latch ? "1" : "0"
                };
                p.connectionHeader = new Header(fields);
            }

            if (!ROS.OK || shuttingDown)
            {
                return;
            }

            if (p.HasSubscribers || p.Latch)
            {
                bool nocopy    = false;
                bool serialize = false;
                if (msg != null && msg.MessageType != "undefined/unknown")
                {
                    p.GetPublishTypes(ref serialize, ref nocopy, msg.MessageType);
                }
                else
                {
                    serialize = true;
                }

                p.Publish(new MessageAndSerializerFunc(msg, serfunc, serialize, nocopy));
            }
            else
            {
                p.IncrementSequence();
            }
        }
Exemple #8
0
 public static bool ExtendCustomType(Type type, byte bSign, SerializeFunc serializeFunc, DeserializeFunc deserializeFunc)
 {
     if (!CheckNativeTypes(bSign))
     {
         return(false);
     }
     if (!BinBuffer.ExtendCustomType(type, bSign, serializeFunc))
     {
         return(false);
     }
     if (!BinParser.ExtendCustomType(type, bSign, deserializeFunc))
     {
         return(false);
     }
     return(true);
 }
Exemple #9
0
 public static bool ExtendCustomType(Type type, byte bSign, SerializeFunc func)
 {
     customTypeExtends[type] = new CustomType(type, bSign, func, null);
     return(true);
 }