コード例 #1
0
        public override byte[] Serialize(bool partofsomethingelse)
        {
            int  currentIndex = 0, length = 0;
            bool hasmetacomponents = false;

            byte[]        thischunk, scratch1, scratch2;
            List <byte[]> pieces = new List <byte[]>();
            GCHandle      h;

            //header
            if (header == null)
            {
                header = new Header();
            }
            pieces.Add(header.Serialize(true));
            //height
            scratch1 = new byte[Marshal.SizeOf(typeof(uint))];
            h        = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
            Marshal.StructureToPtr(height, h.AddrOfPinnedObject(), false);
            h.Free();
            pieces.Add(scratch1);
            //width
            scratch1 = new byte[Marshal.SizeOf(typeof(uint))];
            h        = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
            Marshal.StructureToPtr(width, h.AddrOfPinnedObject(), false);
            h.Free();
            pieces.Add(scratch1);
            //fields
            hasmetacomponents |= true;
            if (fields == null)
            {
                fields = new Messages.sensor_msgs.PointField[0];
            }
            pieces.Add(BitConverter.GetBytes(fields.Length));
            for (int i = 0; i < fields.Length; i++)
            {
                //fields[i]
                if (fields[i] == null)
                {
                    fields[i] = new Messages.sensor_msgs.PointField();
                }
                pieces.Add(fields[i].Serialize(true));
            }
            //is_bigendian
            thischunk    = new byte[1];
            thischunk[0] = (byte)((bool)is_bigendian ? 1 : 0);
            pieces.Add(thischunk);
            //point_step
            scratch1 = new byte[Marshal.SizeOf(typeof(uint))];
            h        = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
            Marshal.StructureToPtr(point_step, h.AddrOfPinnedObject(), false);
            h.Free();
            pieces.Add(scratch1);
            //row_step
            scratch1 = new byte[Marshal.SizeOf(typeof(uint))];
            h        = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
            Marshal.StructureToPtr(row_step, h.AddrOfPinnedObject(), false);
            h.Free();
            pieces.Add(scratch1);
            //data
            hasmetacomponents |= false;
            if (data == null)
            {
                data = new byte[0];
            }
            pieces.Add(BitConverter.GetBytes(data.Length));
            pieces.Add((byte[])data);
            //is_dense
            thischunk    = new byte[1];
            thischunk[0] = (byte)((bool)is_dense ? 1 : 0);
            pieces.Add(thischunk);
            //combine every array in pieces into one array and return it
            int __a_b__f = pieces.Sum((__a_b__c) => __a_b__c.Length);
            int __a_b__e = 0;

            byte[] __a_b__d = new byte[__a_b__f];
            foreach (var __p__ in pieces)
            {
                Array.Copy(__p__, 0, __a_b__d, __a_b__e, __p__.Length);
                __a_b__e += __p__.Length;
            }
            return(__a_b__d);
        }