Esempio n. 1
0
        /// <summary>
        /// Serialize all SyncObjs on this NetObj
        /// </summary>
        public SerializationFlags OnSerialize(int frameId, byte[] buffer, ref int bitposition, SerializationFlags writeFlags)
        {
            //if ((writeFlags & SerializationFlags.NewConnection) != 0)
            //	Debug.LogError("NEW CONN " +writeFlags);

            SerializationFlags flags = 0;

#if SNS_WARNINGS
            /// Integrity check
            buffer.Write(111, ref bitposition, 8);
#endif

            /// Serialize Pack Objects
            int prevFrameId = ((frameId == 0) ? SimpleSyncSettings.FrameCount : frameId) - 1;
            int pcnt        = packObjRecords.Count;
            for (int i = 0; i < pcnt; ++i)
            {
                var p      = packObjRecords[i];
                var pframe = p.packFrames[frameId];

                /// make placeholder for mask bits (we don't know them yet)
                int mcnt    = p.info.fieldCount;
                int maskpos = bitposition;
                bitposition += mcnt;

                int maskOffset = 0;
                flags |= p.info.PackFrameToBuffer(pframe, p.packFrames[prevFrameId], ref pframe.mask, ref maskOffset, buffer, ref bitposition, frameId, writeFlags);

                /// go back and write the mask bits
                for (int m = 0; m < mcnt; ++m)
                {
                    buffer.WriteBool(pframe.mask[m], ref maskpos);
                }
            }

#if SNS_WARNINGS
            /// Integrity check
            buffer.Write(123, ref bitposition, 8);
#endif

            /// Serialize SyncComponents
            int cnt = onNetSerializeCallbacks.Count;
            for (int i = 0; i < cnt; ++i)
            {
#if SNS_REPORTS && (UNITY_EDITOR || DEVELOPMENT_BUILD)
                int holdpos = bitposition;
                flags |= onNetSerialize[i].OnNetSerialize(frameId, buffer, ref bitposition);
                SimpleDataMonitor.AddData(onNetSerialize[i] as ISyncObject, bitposition - holdpos);
#else
                flags |= onNetSerializeCallbacks[i].OnNetSerialize(frameId, buffer, ref bitposition, writeFlags);
#endif
            }

#if SNS_WARNINGS
            /// Integrity check
            buffer.Write(234, ref bitposition, 8);
#endif

            return(flags);
        }
Esempio n. 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int nFramesToCapture = Convert.ToInt32(nFramesToCaptureText.Text);
                _framesToCapture = nFramesToCapture;
                int nMemoryFrames = Convert.ToInt32(nMemoryFramesText.Text);

                SerializationFlags serializationFlags =
                    new SerializationFlags(ColorBox.IsChecked == true,
                                           DepthBox.IsChecked == true,
                                           InfraredBox.IsChecked == true,
                                           SkeletonBox.IsChecked == true,
                                           DepthMappingBox.IsChecked == true,
                                           BodyIndexBox.IsChecked == true);
                _captureController.StartCapture(serializationFlags, nMemoryFrames, nFramesToCapture);
            }
            catch (Exception ex)
            {
                // Catch those Exceptions we know can happen
                if (ex is FormatException || ex is ArgumentException || ex is ArgumentOutOfRangeException ||
                    ex is OverflowException || ex is InvalidOperationException)
                {
                    Console.WriteLine("Exception thrown");
                    MessageBox.Show(ex.Message);
                    return;
                }

                // Other type of Exception, so rethrow it
                throw;
            }
        }
Esempio n. 3
0
        public SerializationFlags Serialize(byte[] buffer, ref int bitposition, int bitsForColliderId)
        {
            SerializationFlags flags = SerializationFlags.None;

            if (nearestOnly)
            {
                if (nearestIndex != -1)
                {
                    buffer.WriteBool(true, ref bitposition);
                    hits[nearestIndex].Serialize(buffer, ref bitposition, bitsForHitGroupMask, bitsForColliderId);
                    flags = SerializationFlags.HasChanged;
                }
                else
                {
                    buffer.WriteBool(false, ref bitposition);
                }
            }
            else
            {
                int cnt = hits.Count;
                for (int i = 0; i < hits.Count; ++i)
                {
                    buffer.WriteBool(true, ref bitposition);
                    hits[i].Serialize(buffer, ref bitposition, bitsForHitGroupMask, bitsForColliderId);
                    flags = SerializationFlags.HasChanged;
                }
                buffer.WriteBool(false, ref bitposition);
            }

            return(flags);
        }
Esempio n. 4
0
        public SerializationFlags Deserialize(byte[] buffer, ref int bitposition, int bitsForColliderId)
        {
            hits.Clear();
            SerializationFlags flags = SerializationFlags.None;

            //bool nearestOnly = definition.hitscanType.IsCast() && definition.nearestOnly;
            if (nearestOnly)
            {
                if (buffer.ReadBool(ref bitposition))
                {
                    hits.Add(NetworkHit.Deserialize(buffer, ref bitposition, bitsForHitGroupMask, bitsForColliderId));
                    flags        = SerializationFlags.HasChanged;
                    nearestIndex = 0;
                }
                else
                {
                    nearestIndex = -1;
                }
            }
            else
            {
                while (buffer.ReadBool(ref bitposition))
                {
                    hits.Add(NetworkHit.Deserialize(buffer, ref bitposition, bitsForHitGroupMask, bitsForColliderId));
                    flags = SerializationFlags.HasChanged;
                }
            }

            return(flags);
        }
Esempio n. 5
0
        public SerializationFlags Unpack(ref List <Int32> value, BitArray isCompleteMask, byte[] buffer, ref int bitposition, int frameId, SerializationFlags writeFlags)
        {
            //bool notforced = !IsForced(frameId, writeFlags);
            bool isKeyframe = IsKeyframe(frameId);

            SerializationFlags flags = SerializationFlags.None;

            var isComplete = SerializationFlags.IsComplete;

            for (int i = 0, cnt = value.Count; i < cnt; ++i)
            {
                if (!isKeyframe)
                {
                    if (!buffer.ReadBool(ref bitposition))
                    {
                        isComplete        = SerializationFlags.None;
                        isCompleteMask[i] = false;
                        //value[i] = prevValue[i];
                        continue;
                    }
                }

                isCompleteMask[i] = true;

                value[i] = buffer.ReadSignedPackedBytes(ref bitposition, bitCount);

                flags |= SerializationFlags.HasContent;
            }

            //Debug.LogError("Unpack List DES " + frameId + " <b>" + value[0] +":"+ value[1] + ":" + value[2] + "</b> " + " flgs: " + (flags | isComplete));
            //if (isComplete == SerializationFlags.IsComplete)
            //	Debug.LogError("Complete Synclist");

            return(flags | isComplete);
        }
Esempio n. 6
0
 public SerializationSettings(SerializationFlags flags = 0)
 {
     this.Flags = flags;
     this.PartialSerialization = false;
     this.InternalObjects      = null;
     this.DistributedFolder    = string.Empty;
 }
Esempio n. 7
0
        public SerializationFlags OnNetDeserialize(int originFrameId, int localFrameId, byte[] buffer, ref int bitposition, FrameArrival arrival)
        {
            WeaponFrame        frame = frames[localFrameId];
            SerializationFlags flags = SerializationFlags.None;

            if (buffer.ReadBool(ref bitposition))
            {
                frame.triggerMask = buffer.ReadUInt32(ref bitposition, sendEveryXTick);
                flags            |= SerializationFlags.HasChanged /*| SerializationFlags.ForceReliable*/;
            }
            else
            {
                frame.triggerMask = 0;
            }

            frame.hitmask = (uint)buffer.Read(ref bitposition, sendEveryXTick);

            for (int i = 0; i < sendEveryXTick; ++i)
            {
                if ((frame.hitmask & (1 << i)) != 0)
                {
                    flags |= frame.netHits[i].Deserialize(buffer, ref bitposition, NetObj.bitsForColliderIndex);
                }
            }

            frame.content = flags == SerializationFlags.None ? FrameContents.Empty : FrameContents.Complete;
            return(flags);
        }
Esempio n. 8
0
        private int Read(byte[] buffer, ref int bitposition, int frameId, SerializationFlags writeFlags)
        {
            if (indicatorBits == IndicatorBits.IsZero)
            {
                if (buffer.Read(ref bitposition, 1) == 0)
                {
                    return(0);
                }
            }
            else if (indicatorBits == IndicatorBits.IsZeroMidMinMax)
            {
                ulong indicator = buffer.Read(ref bitposition, 2);
                switch (indicator)
                {
                case 0:
                    return(0);

                case 1:
                    return(min);

                case 2:
                    return(max);
                }
            }

            if (bitCount < 16)
            {
                return((int)buffer.Read(ref bitposition, bitCount) + smallest);
            }
            else
            {
                return((int)((long)buffer.ReadPackedBytes(ref bitposition, bitCount) + smallest));
            }
        }
Esempio n. 9
0
        public SerializationFlags OnNetDeserialize(int originFrameId, byte[] buffer, ref int bitposition, FrameArrival arrival)
        {
            Frame frame = frames[originFrameId];

            if (!buffer.ReadBool(ref bitposition))
            {
                //if (GetComponent<SyncPickup>())
                //    Debug.LogError(originFrameId + " No Content");

                return(SerializationFlags.None);
            }

            SerializationFlags flags = SerializationFlags.HasContent;

            /// Read State
            frame.state = (ObjState)buffer.Read(ref bitposition, 6);

            bool isAttached = (frame.state & ObjState.Mounted) != 0;

            if (!isAttached)
            {
                frame.content = FrameContents.Complete;
            }
            else if (IsKeyframe(originFrameId) || buffer.Read(ref bitposition, 1) == 1)
            {
                /// Read attached
                if ((frame.state & ObjState.Mounted) != 0)
                {
                    frame.mountToViewID = (int?)buffer.ReadPackedBytes(ref bitposition, 32);
                    if (bitsForMountType > 0)
                    {
                        int mountidx    = (int)buffer.Read(ref bitposition, bitsForMountType);
                        int mountTypeId = indexToMountTypeId[mountidx];
                        frame.mountTypeId = (int?)mountTypeId;
                    }
                    else
                    {
                        frame.mountTypeId = 0;
                    }
                }
                frame.content = FrameContents.Complete;
            }

            /// State is attached, but because this is a delta frame the parent info is missing
            else
            {
                frame.mountToViewID = null;
                frame.mountTypeId   = null;
                frame.content       = FrameContents.Partial;
            }

            //if (GetComponent<SyncPickup>())
            //    Debug.Log(Time.time + " " + flags + " " + name + " <b> fr: " + frame.frameId + " <color=purple>DES STATE</color></b> " + frame.content + " " + frame.state +
            //        ((frame.state & ObjState.Visible) != 0 ? " VISIBLE " : " ") +
            //        ((frame.state & ObjState.Mounted) != 0 ? " MOUNTED " + frame.mountToViewID : " ")
            //        );

            return(flags);
        }
Esempio n. 10
0
            public static MemberFormatter CreateDistributed(MemberInfo memberInfo, SerializationFlags flags, string subPath)
            {
                var dataType        = GetDataType(memberInfo);
                var memberFormatter = typeof(DistributedMemberFormatter <>).MakeGenericType(dataType);
                var ctor            = memberFormatter.GetConstructor(new Type[] { memberInfo.GetType(), typeof(SerializationFlags), typeof(string) });

                return(ctor.Invoke(new object[] { memberInfo, flags, subPath }) as MemberFormatter);
            }
Esempio n. 11
0
        /// <summary>
        /// This function starts a new capture with the specified number of buffers available.
        /// A new Shot (with the specified shot definition) will be added to the Sessions List of Shots
        /// </summary>
        /// <param name="nMemoryFrames">How many buffers should be used for caching the incoming frames before they are serialized</param>
        /// <param name="nFramesToCapture">Optional parameter: How many frames are supposed to be captured. If not set, the default is 0
        /// and the capture continues until the buffer is full or until the user presses the stop button</param>
        /// <param name="serializationFlags">Struct containing information about which data to save to disk</param>
        public void StartCapture(SerializationFlags serializationFlags, int nMemoryFrames, int nFramesToCapture = 0)
        {
            ShotDefinitionVariableFrames newShot = new ShotDefinitionVariableFrames(nFramesToCapture, nMemoryFrames, serializationFlags);

            _session.AddShot(newShot);
            _sessionManager.PrepareForNextShot();
            _sessionManager.CaptureShot();
        }
 public DistributedMemberFormatter(PropertyInfo propertyInfo, SerializationFlags flags, string subPath)
 {
     this.Flags      = flags;
     this.Getter     = propertyInfo.GetValue;
     this.Setter     = propertyInfo.SetValue;
     this.MemberName = propertyInfo.Name;
     this.SubPath    = subPath;
 }
Esempio n. 13
0
 public SerializationSettings(SerializationFlags flags, GuidObject internalObject)
 {
     this.Flags = flags;
     this.PartialSerialization = true;
     this.InternalObjects      = new HashSet <GuidObject>();
     this.InternalObjects.Add(internalObject);
     this.DistributedFolder = string.Empty;
 }
        public SerializationFlags Unpack(ref Double value, byte[] buffer, ref int bitposition, int frameId, SerializationFlags writeFlags)
        {
            float fval = 0;

            SerializationFlags flag = Unpack(ref fval, buffer, ref bitposition, frameId, writeFlags);

            value = fval;
            return(flag);
        }
Esempio n. 15
0
        public byte[] SerializeGroupToBytes(OpenSim.Region.Framework.Scenes.SceneObjectGroup group, SerializationFlags flags)
        {
            Serialization.SceneObjectGroupSnapshot snap = Serialization.SceneObjectGroupSnapshot.FromSceneObjectGroup(group, flags);

            using (MemoryStream ms = new MemoryStream())
            {
                ProtoBuf.Serializer.Serialize<Serialization.SceneObjectGroupSnapshot>(ms, snap);
                return ms.ToArray();
            }
        }
Esempio n. 16
0
        public SerializationFlags OnNetDeserialize(int originFrameId, int localFrameId, byte[] buffer, ref int bitposition, FrameArrival arrival)
        {
            Frame frame = frames[localFrameId];

            SerializationFlags flags = SerializationFlags.HasChanged;

            /// Read State
            frame.state = (ObjState)buffer.Read(ref bitposition, 5);

            bool isAttached = (frame.state & ObjState.Attached) != 0;

            if (!isAttached)
            {
                frame.content = FrameContents.Complete;
            }
            else if (IsKeyframe(originFrameId) || buffer.Read(ref bitposition, 1) == 1)
            {
                ///// Read isRespawn bool
                //frame.respawn = buffer.Read(ref bitposition, 1) == 0 ? false : true;

                /// Read attached
                if ((frame.state & ObjState.Attached) != 0)
                {
                    frame.attachedToNetId = (int?)buffer.ReadPackedBytes(ref bitposition, 32);
                    if (bitsForMountType > 0)
                    {
                        int mountidx    = (int)buffer.Read(ref bitposition, bitsForMountType);
                        int mountTypeId = indexToMountTypeId[mountidx];
                        frame.attachedToMountTypeId = (int?)mountTypeId;
                    }
                    else
                    {
                        frame.attachedToMountTypeId = 0;
                    }
                }


                frame.content = FrameContents.Complete;
            }

            /// State is attached, but because this is a delta frame the parent info is missing
            else
            {
                frame.attachedToNetId       = null;
                frame.attachedToMountTypeId = null;
                frame.content = FrameContents.Partial;
            }

            //if (GetComponent<SyncPickup>())
            //	Debug.Log(Time.time + " " + name + " <b>[" + frame.frameId + "] DES State </b> " + frame.state + " " +
            //		(frame.isCompleteFrame ? (frame.attachedToNetId + ":" + frame.attachedToMountTypeId) : " empty"));


            return(flags);
        }
Esempio n. 17
0
        /// <summary>
        /// Creates a new snapshot from the given group
        /// </summary>
        /// <param name="sog"></param>
        /// <returns></returns>
        public static SceneObjectGroupSnapshot FromSceneObjectGroup(SceneObjectGroup sog, SerializationFlags flags)
        {
            SceneObjectGroupSnapshot snapshot = new SceneObjectGroupSnapshot
            {
                RootPart = SceneObjectPartSnapshot.FromSceneObjectPart(sog.RootPart, flags)
            };

            var parts = sog.GetParts();
            SceneObjectPartSnapshot[] partsSnap;

            //do we have more than just the root?
            if (parts.Count > 1)
            {
                List<SceneObjectPartSnapshot> partsCollect = new List<SceneObjectPartSnapshot>();

                foreach (SceneObjectPart part in parts)
                {
                    if (!part.IsRootPart())
                    {
                        partsCollect.Add(SceneObjectPartSnapshot.FromSceneObjectPart(part, flags));
                    }
                }

                partsSnap = partsCollect.ToArray();
            }
            else
            {
                //nope, just the root
                partsSnap = new SceneObjectPartSnapshot[0];
            }

            snapshot.ChildParts = partsSnap;

            if (sog.IsAttachment && sog.HasGroupChanged)
            {
                snapshot.TaintedAttachment = true;
            }
            else
            {
                snapshot.TaintedAttachment = false;
            }

            if (sog.IsAttachment && sog.IsTempAttachment)
            {
                snapshot.TempAttachment = true;
            }
            else
            {
                snapshot.TempAttachment = false;
            }


            return snapshot;
        }
Esempio n. 18
0
 public IEnumerable <MemberFormatter> GetFormatters(SerializationFlags flags)
 {
     foreach (var group in MemberFormatterGroups)
     {
         var formatter = group.GetFormatter(flags);
         if (formatter != null)
         {
             yield return(formatter);
         }
     }
 }
Esempio n. 19
0
 private MemberFormatter GetFormatter(int index, SerializationFlags flags)
 {
     if (index < MemberFormatterGroups.Length)
     {
         return(MemberFormatterGroups[index]?.GetFormatter(flags));
     }
     else
     {
         return(null);
     }
 }
Esempio n. 20
0
 public SerializationSettings(SerializationFlags flags, IEnumerable <GuidObject> internalObjects)
 {
     this.Flags = flags;
     this.PartialSerialization = true;
     this.InternalObjects      = new HashSet <GuidObject>();
     foreach (var guidObject in internalObjects)
     {
         this.InternalObjects.Add(guidObject);
     }
     this.DistributedFolder = string.Empty;
 }
Esempio n. 21
0
        public byte[] SerializeObjectToBytes(OpenSim.Region.Framework.Scenes.CoalescedObject csog, SerializationFlags flags)
        {
            Serialization.CoalescedObjectSnapshot snap = Serialization.CoalescedObjectSnapshot.FromCoalescedObject(csog, flags);

            using (MemoryStream ms = new MemoryStream())
            {
                ProtoBuf.Serializer.Serialize<Serialization.CoalescedObjectSnapshot>(ms, snap);

                return ms.ToArray();
            }
        }
Esempio n. 22
0
        public virtual SerializationFlags OnNetSerialize(int frameId, byte[] buffer, ref int bitposition, SerializationFlags writeFlags)
        {
            /// TODO: This is ignoring keyframe setting

            Frame frame = frames[frameId];
            SerializationFlags flags = SerializationFlags.None;

            bool iskeyframe = IsKeyframe(frameId);

            if (!iskeyframe)
            {
                return(flags);
            }

            if (respawnEnable)
            {
                /// Respawn
                int ticks = frame.ticksUntilRespawn;

                if (ticks >= 0)
                {
                    /// non -1 counter bool
                    buffer.WriteBool(true, ref bitposition);
                    buffer.Write((ulong)ticks, ref bitposition, bitsForTicksUntilRespawn);
                    flags |= SerializationFlags.HasChanged;
                }
                else
                {
                    /// non -1 counter bool
                    buffer.WriteBool(false, ref bitposition);
                }
            }

            if (despawnEnable)
            {
                /// Despawn
                int ticks = frame.ticksUntilDespawn;
                if (ticks >= 0)
                {
                    /// non -1 counter bool
                    buffer.WriteBool(true, ref bitposition);
                    buffer.Write((ulong)ticks, ref bitposition, bitsForTicksUntilDespawn);

                    flags |= SerializationFlags.HasChanged;
                }
                else
                {
                    /// non -1 counter bool
                    buffer.WriteBool(false, ref bitposition);
                }
            }

            return(flags);
        }
 public MemberFormatter GetFormatter(SerializationFlags flags)
 {
     foreach (var formatter in this)
     {
         if (flags.HasFlag(formatter.Flags))
         {
             return(formatter);
         }
     }
     return(null);
 }
Esempio n. 24
0
        public int WriteMembers(SerializationFlags flags, object instance, ref byte[] bytes, int offset, IFormatterResolver formatterResolver, bool recursive = true)
        {
            var startOffset = offset;

            if (BaseMeta != null && recursive)
            {
                offset += BaseMeta.WriteMembers(flags, instance, ref bytes, offset, formatterResolver);
            }

            if (Flags.IsSerializable() && !Flags.IsSkipWriting())
            {
                if (MemberFormatterGroups == null)
                {
                    offset += MessagePackBinary.WriteNil(ref bytes, offset);
                }
                else
                {
                    var notNilCount = 0;
                    var formatters  = new MemberFormatter[MemberFormatterGroups.Length];
                    for (int i = 0; i < MemberFormatterGroups.Length; i++)
                    {
                        var formatter = MemberFormatterGroups[i]?.GetFormatter(flags);
                        if (formatter != null)
                        {
                            formatters[i] = formatter;
                            notNilCount   = i + 1;
                        }
                    }

                    bool hasAnnotations = Serializer.Instance.State.Settings.Flags.HasFlag(SerializationFlags.Annotations);
                    offset += MessagePackBinary.WriteArrayHeader(ref bytes, offset, notNilCount);
                    for (int i = 0; i < notNilCount; i++)
                    {
                        var formatter = formatters[i];
                        if (formatter == null)
                        {
                            offset += MessagePackBinary.WriteNil(ref bytes, offset);
                        }
                        else
                        {
                            if (hasAnnotations)
                            {
                                offset += MessagePackBinaryExtension.WriteComment(ref bytes, offset, formatter.MemberName + ":");
                            }

                            offset += formatter.Write(instance, ref bytes, offset, formatterResolver);
                        }
                    }
                }
            }

            return(offset - startOffset);
        }
Esempio n. 25
0
        /// <summary>
        /// Serializes a group into a byte array suitable for storage and retrieval from inventory
        /// </summary>
        /// <param name="group"></param>
        /// <returns></returns>
        public byte[] SerializeGroupToInventoryBytes(OpenSim.Region.Framework.Scenes.SceneObjectGroup group, SerializationFlags flags)
        {
            Serialization.SceneObjectGroupSnapshot snap = Serialization.SceneObjectGroupSnapshot.FromSceneObjectGroup(group, flags);

            using (MemoryStream ms = new MemoryStream())
            {
                ms.Write(GROUP_HEADER, 0, GROUP_HEADER.Length);
                snap.SerializeToStream(ms);

                return ms.ToArray();
            }
        }
Esempio n. 26
0
        public object Deserialize(BinaryReader reader, SerializationFlags serializationFlags, Type type)
        {
            var data      = ReadPofFrame(reader, serializationFlags);
            var pofReader = new PofReader(context, slotSourceFactory.CreateWithSingleSlot(data));

            if (serializationFlags.HasFlag(SerializationFlags.Typeless))
            {
                return(pofReader.ReadObjectTypeless(0, type));
            }
            else
            {
                return(pofReader.ReadObject(0));
            }
        }
Esempio n. 27
0
 private static byte[] ReadPofFrame(BinaryReader reader, SerializationFlags serializationFlags)
 {
     byte[] data;
     if (serializationFlags.HasFlag(SerializationFlags.Lengthless))
     {
         data = reader.ReadAllBytes();
     }
     else
     {
         var dataLength = reader.ReadInt32();
         data = reader.ReadBytes(dataLength);
     }
     return(data);
 }
Esempio n. 28
0
        public SerializationFlags Serialize(VitalsData vdata, VitalsData lastVData, byte[] buffer, ref int bitposition, bool keyframe)
        {
            var currdatas = vdata.datas;
            var lastdatas = lastVData.datas;

            SerializationFlags flags = SerializationFlags.None;

            for (int i = 0, cnt = vitalCount; i < cnt; ++i)
            {
                flags |= vitalDefs[i].Serialize(currdatas[i], lastdatas[i], buffer, ref bitposition, keyframe);
            }

            return(flags);
        }
Esempio n. 29
0
        public void ReadMembers(SerializationFlags flags, ref object instance, byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize, bool recursive = true)
        {
            var startOffset = offset;

            if (BaseMeta != null && recursive)
            {
                BaseMeta.ReadMembers(flags, ref instance, bytes, offset, formatterResolver, out readSize);
                offset += readSize;
            }

            if (Flags.IsSerializable() && !Flags.IsSkipReading())
            {
                if (MessagePackBinary.IsNil(bytes, offset))
                {
                    offset += 1;
                }
                else
                {
                    var memberCount = MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);
                    offset += readSize;

                    for (int i = 0; i < memberCount; i++)
                    {
                        var formatter = GetFormatter(i, flags);
                        if (formatter != null)
                        {
                            formatter.Read(ref instance, bytes, offset, formatterResolver, out readSize);
                            offset += readSize;
                        }
                        else
                        {
                            if (MessagePackBinary.IsNil(bytes, offset))
                            {
                                MessagePackBinary.ReadNil(bytes, offset, out readSize);
                                offset += readSize;
                            }
                            else
                            {
                                var message = String.Format("unknown serializaion data: {0}:{1}", Type.Name, i);
                                Logger.Instance.Warning(message);
                                offset += MessagePackBinary.ReadNextBlock(bytes, offset);
                            }
                        }
                    }
                }
            }

            readSize = offset - startOffset;
        }
Esempio n. 30
0
        public static SerializationFlags Pack(ref PackFrame_TestPackObject packable, PackFrame prevFrame, ref FastBitMask128 mask, ref int maskOffset, byte[] buffer, ref int bitposition, int frameId, SerializationFlags writeFlags)
        {
            var prev = prevFrame as PackFrame_TestPackObject;
            SerializationFlags flags = SerializationFlags.None;

            {
                var flag = rotationPacker(ref packable.rotation, prev.rotation, buffer, ref bitposition, frameId, writeFlags);
                mask[maskOffset] = flag != SerializationFlags.None;     flags |= flag; maskOffset++;
            }
            {
                var flag = intorobotoPacker(ref packable.intoroboto, prev.intoroboto, buffer, ref bitposition, frameId, writeFlags);
                mask[maskOffset] = flag != SerializationFlags.None;     flags |= flag; maskOffset++;
            }
            return(flags);
        }
Esempio n. 31
0
        public static CoalescedObjectSnapshot FromCoalescedObject(CoalescedObject csog, SerializationFlags flags)
        {
            List<Tuple<SceneObjectGroupSnapshot, ItemPermissionBlockSnapshot>> snapGroups
                = new List<Tuple<SceneObjectGroupSnapshot, ItemPermissionBlockSnapshot>>();

            foreach (var group in csog.Groups)
            {
                snapGroups.Add(
                    new Tuple<SceneObjectGroupSnapshot, ItemPermissionBlockSnapshot>(
                        SceneObjectGroupSnapshot.FromSceneObjectGroup(group, flags),
                        ItemPermissionBlockSnapshot.FromItemPermissionBlock(csog.FindPermissions(group.UUID)))
                    );
            }

            return new CoalescedObjectSnapshot { GroupsWithPermissions = snapGroups.ToArray() };
        }
Esempio n. 32
0
        public static CoalescedObjectSnapshot FromGroups(IEnumerable<Tuple<SceneObjectGroup,ItemPermissionBlock>> groups, SerializationFlags flags)
        {
            List<Tuple<SceneObjectGroupSnapshot, ItemPermissionBlockSnapshot>> snapGroups
                = new List<Tuple<SceneObjectGroupSnapshot, ItemPermissionBlockSnapshot>>();

            foreach (var group in groups)
            {
                snapGroups.Add(
                    new Tuple<SceneObjectGroupSnapshot, ItemPermissionBlockSnapshot>(
                        SceneObjectGroupSnapshot.FromSceneObjectGroup(group.Item1, flags),
                        ItemPermissionBlockSnapshot.FromItemPermissionBlock(group.Item2))
                    );
            }

            return new CoalescedObjectSnapshot { GroupsWithPermissions = snapGroups.ToArray() };
        }
Esempio n. 33
0
        public virtual SerializationFlags OnNetDeserialize(int sourceFrameId, int originFrameId, int localFrameId, byte[] buffer, ref int bitposition)
        {
            Frame frame = frames[localFrameId];
            SerializationFlags flags = SerializationFlags.None;

            bool iskeyframe = IsKeyframe(originFrameId);

            if (!iskeyframe)
            {
                frame.content = FrameContents.Empty;
                return(flags);
            }

            if (respawnEnable)
            {
                /// Read ticksToRespawn
                if (buffer.ReadBool(ref bitposition))
                {
                    frame.ticksUntilRespawn = (int)buffer.Read(ref bitposition, bitsForTicksUntilRespawn);
                    flags |= SerializationFlags.HasChanged;
                }
                else
                {
                    frame.ticksUntilRespawn = -1;
                }
            }

            if (despawnEnable)
            {
                if (buffer.ReadBool(ref bitposition))
                {
                    frame.ticksUntilDespawn = (int)buffer.Read(ref bitposition, bitsForTicksUntilDespawn);
                    flags |= SerializationFlags.HasChanged;
                }
                else
                {
                    frame.ticksUntilDespawn = -1;
                }
            }

            frame.content = FrameContents.Complete;
            return(flags);
        }
Esempio n. 34
0
        public void Serialize(BinaryWriter writer, object portableObject, SerializationFlags serializationFlags)
        {
            var slotDestination = new SlotDestination();
            var pofWriter       = new PofWriter(context, slotDestination);

            if (serializationFlags.HasFlag(SerializationFlags.Typeless))
            {
                pofWriter.WriteObjectTypeless(0, portableObject);
            }
            else
            {
                pofWriter.WriteObject(0, portableObject);
            }

            var data = slotDestination[0];

            writer.Write((int)data.Length);
            writer.Write(data);
        }
Esempio n. 35
0
        public bool IsForcedClass <T>(int frameId, T value, T prevValue, SerializationFlags writeFlags) where T : class
        {
            if (syncAs == SyncAs.Trigger)
            {
                Debug.LogError("Reference type " + typeof(T).Name + " cannot be set to SyncAs.Trigger. This PackAttribute setting only applies to structs.");
                /// TODO: this will create garbage for ref types.
                return(true);
            }

            /// always true if 1
            if (keyRate == KeyRate.Every)
            {
                return(true);
            }

            /// always true if forced
            if ((writeFlags & SerializationFlags.Force) != 0)
            {
                return(true);
            }


            /// if no keyframes are used, still force on new connections
            if (keyRate == 0)
            {
                if ((writeFlags & SerializationFlags.NewConnection) != 0)
                {
                    return(true);
                }
            }

            if (keyRate != KeyRate.Never && frameId % (int)keyRate == 0)
            {
                return(true);
            }

            if (!value.Equals(prevValue))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 36
0
        public bool IsForced <T>(int frameId, T value, T prevValue, SerializationFlags writeFlags) where T : struct
        {
            if (syncAs == SyncAs.Trigger)
            {
                /// TODO: this will create garbage for ref types.
                return(!value.Equals(new T()));
            }

            /// always true if 1
            if (keyRate == KeyRate.Every)
            {
                return(true);
            }

            /// always true if forced
            if ((writeFlags & SerializationFlags.Force) != 0)
            {
                return(true);
            }


            /// if no keyframes are used, still force on new connections
            if (keyRate == 0)
            {
                if ((writeFlags & SerializationFlags.NewConnection) != 0)
                {
                    return(true);
                }
            }

            if (keyRate != KeyRate.Never && frameId % (int)keyRate == 0)
            {
                return(true);
            }

            if (!value.Equals(prevValue))
            {
                return(true);
            }

            return(false);
        }
        static public SceneObjectPartSnapshot FromSceneObjectPart(SceneObjectPart part, SerializationFlags flags)
        {
            bool serializePhysicsShapes = (flags & SerializationFlags.SerializePhysicsShapes) != 0;
            bool serializeScriptBytecode = (flags & SerializationFlags.SerializeScriptBytecode) != 0;

            StopScriptReason stopScriptReason;
            if ((flags & SerializationFlags.StopScripts) == 0)
            {
                stopScriptReason = StopScriptReason.None;
            }
            else
            {
                if ((flags & SerializationFlags.FromCrossing) != 0)
                    stopScriptReason = StopScriptReason.Crossing;
                else
                    stopScriptReason = StopScriptReason.Derez;
            }

            SceneObjectPartSnapshot partSnap = new SceneObjectPartSnapshot
            {
                AngularVelocity = part.PhysicalAngularVelocity,
                AngularVelocityTarget = part.AngularVelocity,
                BaseMask = part.BaseMask,
                Category = part.Category,
                ClickAction = part.ClickAction,
                CollisionSound = part.CollisionSound.Guid,
                CollisionSoundVolume = part.CollisionSoundVolume,
                CreationDate = part.CreationDate,
                CreatorId = part.CreatorID.Guid,
                Description = part.Description,
                EveryoneMask = part.EveryoneMask,
                Flags = part.Flags,
                GroupId = part.GroupID.Guid,
                GroupMask = part.GroupMask,

                //if this is an attachment, dont fill out the group position. This prevents an issue where
                //a user is crossing to a new region and the vehicle has already been sent. Since the attachment's
                //group position is actually the wearer's position and the wearer's position is the vehicle position,
                //trying to get the attachment grp pos triggers an error and a ton of log spam.
                GroupPosition = part.ParentGroup.IsAttachment ? OpenMetaverse.Vector3.Zero : part.GroupPosition, 

                HoverText = part.Text,
                Id = part.UUID.Guid,
                Inventory = TaskInventorySnapshot.FromTaskInventory(part),
                KeyframeAnimation = KeyframeAnimationSnapshot.FromKeyframeAnimation(part.KeyframeAnimation),
                LastOwnerId = part.LastOwnerID.Guid,
                LinkNumber = part.LinkNum,
                LocalId = part.LocalId,
                Material = (OpenMetaverse.Material)part.Material,
                MediaUrl = part.MediaUrl,
                Name = part.Name,
                NextOwnerMask = part.NextOwnerMask,
                ObjectFlags = (OpenMetaverse.PrimFlags)part.ObjectFlags,
                ObjectSaleType = part.ObjectSaleType,
                OffsetPosition = part.OffsetPosition,
                OwnerId = part.OwnerID.Guid,
                OwnerMask = part.OwnerMask,
                OwnershipCost = part.OwnershipCost,
                ParentId = part.ParentID,
                ParticleSystem = part.ParticleSystem,
                PassTouches = part.PassTouches,
                PayPrice = part.PayPrice,
                RegionHandle = part.RegionHandle,
                RotationOffset = part.RotationOffset,
                SalePrice = part.SalePrice,
                SavedAttachmentPoint = part.SavedAttachmentPoint,
                SavedAttachmentPos = part.SavedAttachmentPos,
                SavedAttachmentRot = part.SavedAttachmentRot,
                Scale = part.Scale,
                ScriptAccessPin = part.ScriptAccessPin,
                SerializedPhysicsData = part.SerializedPhysicsData,
                ServerWeight = part.ServerWeight,
                Shape = PrimShapeSnapshot.FromShape(part.Shape),
                SitName = part.SitName,
                SitTargetOrientation = part.SitTargetOrientation,
                SitTargetPosition = part.SitTargetPosition,
                Sound = part.Sound.Guid,
                SoundFlags = part.SoundOptions,
                SoundGain = part.SoundGain,
                SoundRadius = part.SoundRadius,
                StreamingCost = part.StreamingCost,
                TextColor = part.TextColor,
                TextureAnimation = part.TextureAnimation,
                TouchName = part.TouchName,
                Velocity = part.Velocity,
                FromItemId = part.FromItemID.Guid
            };

            Dictionary<OpenMetaverse.UUID, byte[]> states;
            Dictionary<OpenMetaverse.UUID, byte[]> byteCode;
            if (serializeScriptBytecode)
            {
                Tuple<Dictionary<OpenMetaverse.UUID, byte[]>, Dictionary<OpenMetaverse.UUID, byte[]>>
                    statesAndBytecode = part.Inventory.GetBinaryScriptStatesAndCompiledScripts(stopScriptReason);

                states = statesAndBytecode.Item1;
                byteCode = statesAndBytecode.Item2;
            }
            else
            {
                states = part.Inventory.GetBinaryScriptStates(stopScriptReason);
                byteCode = null;
            }

            
            partSnap.SerializedScriptStates = new Dictionary<Guid, byte[]>(states.Count);
            foreach (var kvp in states)
            {
                //map from UUID to Guid
                partSnap.SerializedScriptStates[kvp.Key.Guid] = kvp.Value;
            }

            if (byteCode != null)
            {
                partSnap.SeralizedScriptBytecode = new Dictionary<Guid, byte[]>();

                foreach (var kvp in byteCode)
                {
                    //map from UUID to Guid
                    partSnap.SeralizedScriptBytecode[kvp.Key.Guid] = kvp.Value;
                }
            }

            if (serializePhysicsShapes)
            {
                partSnap.SerializedPhysicsShapes = part.SerializedPhysicsShapes;
            }

            return partSnap;
        }
Esempio n. 38
0
 private void SetSerializationFlags(int flags)
 {
     SerializationFlags = (SerializationFlags)flags;
 }
Esempio n. 39
0
 public AsanaDataAttribute(string name, SerializationFlags flags, params string[] fieldsToSerialize)
 {
     Name = name;
     Flags = flags;
     Fields = fieldsToSerialize;
 }
Esempio n. 40
0
 private byte[] DoSerializeSingleGroup(SceneObjectGroup sceneObjectGroup, SerializationFlags flags)
 {
     ISerializationEngine engine;
     if (ProviderRegistry.Instance.TryGet<ISerializationEngine>(out engine))
     {
         return engine.InventoryObjectSerializer.SerializeGroupToInventoryBytes(sceneObjectGroup, flags);
     }
     else
     {
         StopScriptReason reason = SerializationFlagsToStopReason(flags);
         return Utils.StringToBytes(SceneObjectSerializer.ToOriginalXmlFormat(sceneObjectGroup, reason));
     }
 }
Esempio n. 41
0
        private byte[] DoSerializeCoalesced(IList<SceneObjectGroup> items, List<ItemPermissionBlock> itemPermissions, SerializationFlags flags)
        {
            ISerializationEngine engine;
            if (ProviderRegistry.Instance.TryGet<ISerializationEngine>(out engine))
            {
                Dictionary<UUID, ItemPermissionBlock> perms = new Dictionary<UUID,ItemPermissionBlock>();
                for (int i = 0; i < items.Count; i++)
                {
                    perms.Add(items[i].UUID, itemPermissions[i]);
                }

                CoalescedObject csog = new CoalescedObject(items, perms);
                return engine.InventoryObjectSerializer.SerializeCoalescedObjToInventoryBytes(csog, flags);
            }
            else
            {
                StopScriptReason stopScriptReason = SerializationFlagsToStopReason(flags);
                return Utils.StringToBytes(CoalescedSceneObjectSerializer.ToXmlFormat(items, itemPermissions, stopScriptReason));
            }
        }
Esempio n. 42
0
 private StopScriptReason SerializationFlagsToStopReason(SerializationFlags flags)
 {
     if ((flags & SerializationFlags.StopScripts) == 0)
         return StopScriptReason.None;
     if ((flags & SerializationFlags.FromCrossing) != 0)
         return StopScriptReason.Crossing;
     else
         return StopScriptReason.Derez;
 }
Esempio n. 43
0
        public byte[] SerializeCoalescedObjToInventoryBytes(OpenSim.Region.Framework.Scenes.CoalescedObject csog, SerializationFlags flags)
        {
            Serialization.CoalescedObjectSnapshot snap = Serialization.CoalescedObjectSnapshot.FromCoalescedObject(csog, flags);

            using (MemoryStream ms = new MemoryStream())
            {
                ms.Write(COALESCED_HEADER, 0, COALESCED_HEADER.Length);
                snap.SerializeToStream(ms);

                return ms.ToArray();
            }
        }