示例#1
0
        public override uint FromBytes(Binary serializer, Binary.Buffer buffer, uint start)
        {
            uint read = 0;

            byte[] raw_guid;
            byte   channel_type;
            ushort heartbeat_ticks;

            read += serializer.FromBytes(buffer, start + read, out raw_guid);
            read += serializer.FromBytes(buffer, start + read, out channel);
            read += serializer.FromBytes(buffer, start + read, out channel_type);
            read += serializer.FromBytes(buffer, start + read, out heartbeat_ticks);
            read += serializer.FromBytes(buffer, start + read, out autoReconnect);

            guid = new Guid(raw_guid);

            type = (Net.Negotiation.Channel.Type)channel_type;

            if (heartbeat_ticks == ushort.MaxValue)
            {
                heartbeat = new TimeSpan(0, 0, 0, 0, -1);
            }
            else
            {
                heartbeat = new TimeSpan(heartbeat_ticks * 100 * TimeSpan.TicksPerMillisecond);
            }

            return(read);
        }
示例#2
0
        public uint FromBytes(Binary serializer, Binary.Buffer buffer, uint start)
        {
            string raw_type;

            uint read = serializer.FromBytes(buffer, start, out raw_type);

            type = System.Type.GetType(raw_type);

            read += serializer.FromBytes(buffer, start + read, out resolved);

            if (resolved)
            {
                read += serializer.FromBytes(buffer, start + read, out id);
                read += serializer.FromBytes(buffer, start + read, out part);
            }
            else
            {
                int instance_id;

                // This deserialization should never be used in normal case. Serialization of unresolved reference
                // is only usefull to compute the unique hash of each node to group them together. Deserialization
                // is not needed for this process.
                read += serializer.FromBytes(buffer, start + read, out instance_id);
            }

            return(read);
        }
示例#3
0
        public bool Receive(out Message.Base message)
        {
            uint read = 0;
            uint size = 0;

            message = null;

            if (stream != null && parent != null)
            {
                if (ReceiveData(stream, headerBuffer, headerSize))
                {
                    message = Pattern.Factory <Message.Base, byte> .CreateInstance(headerBuffer[0]);

                    size = new Converter32(headerBuffer[1], headerBuffer[2], headerBuffer[3], headerBuffer[4]);

                    Binary.Buffer buffer = parent.Serializer.GetBuffer(size);

                    if (ReceiveData(stream, buffer.Data, size))
                    {
                        read = parent.Serializer.FromBytesOverwrite(buffer, 0, message);
                    }
                }
            }

            return(message != null && read == size);
        }
示例#4
0
 public void ToUnity(Scene scene, Component component, System.Type type)
 {
     using (Binary.Buffer buffer = Module.Import.Binary.serializer.GetBufferFromExistingData(serialized))
     {
         Module.Import.Binary.serializer.FromBytesOverwrite(buffer, 0, component as IBinarySerializable);
     }
 }
示例#5
0
        private string ComputeHash(Scene scene, Transform trans)
        {
            Binary.Buffer buffer = Module.Import.Binary.serializer.GetBuffer(5 * 1024);             // Start with 5 Ko buffer

            uint written = 0;

            foreach (Component component in trans.GetComponents <Component>())
            {
                if (SerializedComponent(component))
                {
                    written += Module.Import.Binary.serializer.ToBytes(ref buffer, written, UnityComponent.FromUnity(scene, component));
                }
            }

            uint size = (uint)System.Text.Encoding.UTF8.GetByteCount(name);

            size += 2 * Binary.Size(Binary.SupportedTypes.UNITY_VECTOR3);
            size += Binary.Size(Binary.SupportedTypes.UNITY_QUATERNION);

            Module.Import.Binary.serializer.ResizeBuffer(ref buffer, written + size);

            written += Module.Import.Binary.serializer.ToBytes(ref buffer, written, trans.name);
            written += Module.Import.Binary.serializer.ToBytes(ref buffer, written, trans.localPosition);
            written += Module.Import.Binary.serializer.ToBytes(ref buffer, written, trans.localRotation);
            written += Module.Import.Binary.serializer.ToBytes(ref buffer, written, trans.localScale);

            return(Hash.ComputeHash(buffer.Data, 0, (int)written));
        }
示例#6
0
            public void FromUnity(Scene scene, Component component, System.Type type)
            {
                // We can not use the 'Serialize' high level method directly as deserialization will require
                // the use of explicit low level 'FromBytesOverwrite'. Therefore, we must do things manually here.

                Binary serializer = Module.Import.Binary.serializer;

                Binary.Buffer buffer = null;

                try
                {
                    buffer = serializer.GetBuffer(Binary.defaultSerializationBufferSize);

                    uint written = serializer.ToBytes(ref buffer, 0, component as IBinarySerializable);

                    serialized = new byte[written];

                    Array.Copy(buffer.Data, serialized, written);
                }
                catch (Exception e)
                {
                    throw new Binary.SerializationException("An error occured during serialization.", e);
                }
                finally
                {
                    if (buffer != null)
                    {
                        buffer.Dispose();
                    }
                }
            }
示例#7
0
            public uint DeserializationCallback(Binary serializer, Binary.Buffer buffer)
            {
                uint read = serializer.FromBytes(buffer, 0, out object d);

                data = d as IBinarySerializable;

                return(read);
            }
示例#8
0
        public override uint FromBytes(Binary serializer, Binary.Buffer buffer, uint start)
        {
            uint read = 0;

            read += serializer.FromBytes(buffer, start + read, out accepted);

            return(read);
        }
示例#9
0
            public uint ToBytes(Binary serializer, ref Binary.Buffer buffer, uint start)
            {
                uint written = serializer.ToBytes(ref buffer, start, (int)topology);

                written += serializer.ToBytes(ref buffer, start + written, triangles);

                return(written);
            }
示例#10
0
            public uint FromBytes(Binary serializer, Binary.Buffer buffer, uint start)
            {
                uint read = serializer.FromBytes(buffer, start, out meshIndex);

                read += serializer.FromBytes(buffer, start + read, out materialsIndexes);

                return(read);
            }
示例#11
0
            public uint ToBytes(Binary serializer, ref Binary.Buffer buffer, uint start)
            {
                uint written = serializer.ToBytes(ref buffer, start, meshIndex);

                written += serializer.ToBytes(ref buffer, start + written, materialsIndexes);

                return(written);
            }
示例#12
0
            public uint ToBytes(Binary serializer, ref Binary.Buffer buffer, uint start)
            {
                uint written = serializer.ToBytes(ref buffer, start, index);

                written += serializer.ToBytes(ref buffer, start + written, offset);
                written += serializer.ToBytes(ref buffer, start + written, scale);

                return(written);
            }
示例#13
0
        /// <summary>
        /// Save all the recorded commands to a file.
        /// Should be called after Stop() and before next Wait().
        /// </summary>
        /// <param name="filename">file path</param>
        public void Save(string filename)
        {
            Binary.Buffer buffer = serializer.Serialize(commands);

            using (FileStream stream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                stream.Write(buffer.Data, 0, (int)buffer.Size);
            }
        }
示例#14
0
            public uint FromBytes(Binary serializer, Binary.Buffer buffer, uint start)
            {
                uint read = 0;

                read += serializer.FromBytes(buffer, start + read, out fields);
                read += serializer.FromBytes(buffer, start + read, out properties);

                return(read);
            }
示例#15
0
            public uint Callback(Binary serializer, ref Binary.Buffer buffer)
            {
                uint written = 0;

                written += serializer.ToBytes(ref buffer, written, Type);
                written += serializer.ToBytes(ref buffer, written, Data);

                return(written);
            }
示例#16
0
            public uint FromBytes(Binary serializer, Binary.Buffer buffer, uint start)
            {
                uint read = serializer.FromBytes(buffer, start, out index);

                read += serializer.FromBytes(buffer, start + read, out offset);
                read += serializer.FromBytes(buffer, start + read, out scale);

                return(read);
            }
示例#17
0
            public uint ToBytes(Binary serializer, ref Binary.Buffer buffer, uint start)
            {
                uint written = 0;

                written += serializer.ToBytes(ref buffer, start + written, fields);
                written += serializer.ToBytes(ref buffer, start + written, properties);

                return(written);
            }
示例#18
0
        public uint ToBytes(Binary serializer, ref Binary.Buffer buffer, uint start)
        {
            uint written = 0;

            written += serializer.ToBytes(ref buffer, start + written, type);
            written += backend.ToBytes(serializer, ref buffer, start + written);

            return(written);
        }
示例#19
0
文件: Scene.cs 项目: clarte53/armine
        public uint ToBytes(Binary serializer, ref Binary.Buffer buffer, uint start)
        {
            uint written = serializer.ToBytes(ref buffer, start, root_node);

            written += serializer.ToBytes(ref buffer, start + written, meshes);
            written += serializer.ToBytes(ref buffer, start + written, materials);
            written += serializer.ToBytes(ref buffer, start + written, textures);

            return(written);
        }
示例#20
0
        public override uint FromBytes(Binary serializer, Binary.Buffer buffer, uint start)
        {
            uint read = 0;

            read += serializer.FromBytes(buffer, start + read, out version);
            read += serializer.FromBytes(buffer, start + read, out username);
            read += serializer.FromBytes(buffer, start + read, out password);

            return(read);
        }
示例#21
0
        public uint FromBytes(Binary serializer, Binary.Buffer buffer, uint start)
        {
            uint read = 0;

            read += serializer.FromBytes(buffer, start + read, out active);

            read += BytesToInfo(serializer, buffer, start + read);

            return(read);
        }
示例#22
0
        public uint ToBytes(Binary serializer, ref Binary.Buffer buffer, uint start)
        {
            uint written = 0;

            written += serializer.ToBytes(ref buffer, start + written, active);

            written += InfoToBytes(serializer, ref buffer, start + written);

            return(written);
        }
            public uint ToBytes(Binary serializer, ref Binary.Buffer buffer, uint start)
            {
                uint written = 0;

                written += serializer.ToBytes(ref buffer, start + written, timestamp);
                written += serializer.ToBytes(ref buffer, start + written, position);
                written += serializer.ToBytes(ref buffer, start + written, rotation);
                written += serializer.ToBytes(ref buffer, start + written, scale);

                return(written);
            }
            public uint FromBytes(Binary serializer, Binary.Buffer buffer, uint start)
            {
                uint read = 0;

                read += serializer.FromBytes(buffer, start + read, out timestamp);
                read += serializer.FromBytes(buffer, start + read, out position);
                read += serializer.FromBytes(buffer, start + read, out rotation);
                read += serializer.FromBytes(buffer, start + read, out scale);

                return(read);
            }
示例#25
0
        public uint ToBytes(Binary serializer, ref Binary.Buffer buffer, uint start)
        {
            uint written = serializer.ToBytes(ref buffer, start, filename);

            written += serializer.ToBytes(ref buffer, start + written, width);
            written += serializer.ToBytes(ref buffer, start + written, height);
            written += serializer.ToBytes(ref buffer, start + written, (int)format);
            written += serializer.ToBytes(ref buffer, start + written, data);

            return(written);
        }
示例#26
0
            public uint ToBytes(Binary serializer, ref Binary.Buffer buffer, uint start)
            {
                uint written = 0;

                written += serializer.ToBytes(ref buffer, start + written, exist);
                written += serializer.ToBytes(ref buffer, start + written, port);
                written += serializer.ToBytes(ref buffer, start + written, info);
                written += serializer.ToBytes(ref buffer, start + written, ComputeControlSum(buffer.Data, start, written));

                return(written);
            }
示例#27
0
            public uint FromBytes(Binary serializer, Binary.Buffer buffer, uint start)
            {
                int topo;

                uint read = serializer.FromBytes(buffer, start, out topo);

                read += serializer.FromBytes(buffer, start + read, out triangles);

                topology = (MeshTopology)topo;

                return(read);
            }
示例#28
0
        public uint FromBytes(Binary serializer, Binary.Buffer buffer, uint start)
        {
            uint read = 0;

            read += serializer.FromBytes(buffer, start + read, out type);

            CreateBackend();

            read += backend.FromBytes(serializer, buffer, start + read);

            return(read);
        }
示例#29
0
        public override uint ToBytes(Binary serializer, ref Binary.Buffer buffer, uint start)
        {
            uint written = 0;

            const uint message_size = sizeof(bool);

            serializer.ResizeBuffer(ref buffer, start + message_size);

            written += serializer.ToBytes(ref buffer, start + written, accepted);

            return(written);
        }
示例#30
0
        public override uint ToBytes(Binary serializer, ref Binary.Buffer buffer, uint start)
        {
            uint written = 0;

            serializer.ResizeBuffer(ref buffer, start + messageSize);

            written += serializer.ToBytes(ref buffer, start + written, guid.ToByteArray());
            written += serializer.ToBytes(ref buffer, start + written, channel);
            written += serializer.ToBytes(ref buffer, start + written, port);

            return(written);
        }