Ejemplo n.º 1
0
        private List <IStreamable> ReceiveObjectList(IZetboxContext ctx, ZetboxStreamReader sr)
        {
            List <IStreamable> result = new List <IStreamable>();
            var cont = sr.ReadBoolean();

            while (cont)
            {
                var objType = sr.ReadSerializableType();

                IStreamable obj = (IStreamable)ctx.Internals().CreateUnattached(_iftFactory(objType.GetSystemType()));
                obj.FromStream(sr);

                result.Add((IStreamable)obj);
                cont = sr.ReadBoolean();
            }
            return(result);
        }
Ejemplo n.º 2
0
        private List <IStreamable> ReceiveObjectList(IZetboxContext ctx, ZetboxStreamReader sr)
        {
            List <IStreamable> result = new List <IStreamable>();
            bool cont                  = sr.ReadBoolean();
            long dbgByteCounter        = 0;
            long dbgObjTypeByteCounter = 0;

            while (cont)
            {
                long dbgCurrentPos = sr.BaseStream.Position;
                var  objType       = sr.ReadSerializableType();
                dbgObjTypeByteCounter += sr.BaseStream.Position - dbgCurrentPos;

                IStreamable obj = (IStreamable)ctx.Internals().CreateUnattached(_iftFactory(objType.GetSystemType()));
                obj.FromStream(sr);
                result.Add((IStreamable)obj);

                cont = sr.ReadBoolean();
                long dbgSize = sr.BaseStream.Position - dbgCurrentPos;
                dbgByteCounter += dbgSize;
            }
            Logging.Facade.DebugFormat("ReceiveObjectList: {0:n0} objects; {1:n0} bytes total size; {2:n0} bytes avg. size / object; Total ObjType size: {3:n0}; {4:n2}% of total", result.Count, dbgByteCounter, (double)dbgByteCounter / (double)result.Count, dbgObjTypeByteCounter, (double)dbgObjTypeByteCounter / (double)dbgByteCounter * 100.0);
            return(result);
        }
Ejemplo n.º 3
0
        public static void AssertCorrectContents <LOCALINTERFACE, ENUMTYPE>(ZetboxStreamReader sr, InterfaceType.Factory iftFactory)
            where LOCALINTERFACE : TestObjClass <LOCALINTERFACE, ENUMTYPE>
            where ENUMTYPE : struct
        {
            Assert.That(sr, Is.Not.Null, "no stream to inspect");

            var objType = sr.ReadSerializableType();

            Assert.That(objType, Is.EqualTo(GetSerializableType <LOCALINTERFACE, ENUMTYPE>(iftFactory)), "wrong interface type found");

            var testObjId = sr.ReadInt32();

            Assert.That(testObjId, Is.EqualTo(TestObjClassId), "wrong object ID found");

            DataObjectState?objectState = null;

            sr.ReadConverter(i => objectState = (DataObjectState)i);
            Assert.That(objectState, Is.EqualTo(TestObjectState), "wrong ObjectState found");

            int accessRights = sr.ReadInt32();

            Assert.That(accessRights, Is.GreaterThan(0), "wrong Access Rights found");

            // TestObjClass

            // BaseTestObjClass Reference
            int?testObjRefId;

            sr.Read(out testObjRefId);
            Assert.That(testObjRefId, Is.EqualTo(TestBaseClassId), "wrong BaseObjClass ID found");

            // StringProp
            string testStringProp;

            sr.Read(out testStringProp);
            Assert.That(testStringProp, Is.EqualTo(TestStringPropValue), "wrong StringProp Value found");

            //// SubClasses are not serialized, but fetched lazily
            //foreach (int subClassID in TestSubClassesIds)
            //{
            //    bool continuationMarkerForSubClasses = false;
            //    BinarySerializer.FromStream(out continuationMarkerForSubClasses, sr);
            //    Assert.That(continuationMarkerForSubClasses, Is.True, "wrong continuation marker for subClassId {0}", subClassID);

            //    int readSubClassId;
            //    BinarySerializer.FromStream(out readSubClassId, sr);
            //    Assert.That(readSubClassId, Is.EqualTo(readSubClassId), "wrong subClassId read", subClassID);
            //}

            //bool continuationMarkerAfterSubClasses = false;
            //BinarySerializer.FromStream(out continuationMarkerAfterSubClasses, sr);
            //Assert.That(continuationMarkerAfterSubClasses, Is.False, "wrong continuation marker after subClassIds");

            // TestEnumProp
            var testEnum = (TestEnum)sr.ReadInt32();

            Assert.That(testEnum, Is.EqualTo(TestEnum.TestSerializationValue), "wrong enum value found");

            // TestNames
            for (int i = 0; i < TestTestNamesIds.Length; i++)
            {
                var continuationMarkerForCes = sr.ReadBoolean();
                Assert.That(continuationMarkerForCes, Is.True, "wrong continuation marker for testName #{0}", i);

                var ceType = sr.ReadSerializableType();
                Assert.That(ceType, Is.EqualTo(GetSerializableCollectionEntryType <LOCALINTERFACE, ENUMTYPE>(iftFactory)), "wrong interface type found for collection entry #{0}", i);

                var readCeId = sr.ReadInt32();
                Assert.That(readCeId, Is.EqualTo(TestTestNamesIds[i]), "wrong id read for collection entry #{0}", i);

                DataObjectState?ceObjectState = null;
                sr.ReadConverter(read => ceObjectState = (DataObjectState)read);
                Assert.That(ceObjectState, Is.EqualTo(TestCollectionEntryState), "wrong ObjectState found for collection entry #{0}", i);

                var readCeAccessRights = sr.ReadInt32();
                Assert.That(readCeAccessRights, Is.GreaterThan(0), "wrong access rights for collection entry #{0}", i);

                var readValue = sr.ReadString();
                Assert.That(readValue, Is.EqualTo(TestTestNamesValues[i]), "wrong value read for collection entry #{0}", i);
            }

            var continuationMarkerAfterCes = sr.ReadBoolean();

            Assert.That(continuationMarkerAfterCes, Is.False, "wrong continuation marker after testNames collection entries");
        }