Beispiel #1
0
        int ITypeDescriber.ToBuffer(object instance, byte[] buffer, int begin)
        {
            try
            {
                ValidObjectSet set    = _GetSet(instance);
                int            offset = begin;
                offset += Varint.NumberToBuffer(buffer, offset, set.TotalLength);
                offset += Varint.NumberToBuffer(buffer, offset, set.ValidLength);


                for (int i = 0; i < set.ValidObjects.Length; i++)
                {
                    int    index = set.ValidObjects[i].Index;
                    object obj   = set.ValidObjects[i].Object;
                    offset += Varint.NumberToBuffer(buffer, offset, index);
                    Type           objType   = obj.GetType();
                    ITypeDescriber describer = _TypeSet.Get(objType);
                    offset += _TypeSet.Get().ToBuffer(objType, buffer, offset);
                    offset += describer.ToBuffer(obj, buffer, offset);
                }

                return(offset - begin);
            }
            catch (Exception ex)
            {
                throw new DescriberException(typeof(ArrayDescriber), _Type, "ToBuffer", ex);
            }
        }
Beispiel #2
0
        int ITypeDescriber.GetByteCount(object instance)
        {
            ValidObjectSet set = _GetSet(instance);


            int lenCount   = Varint.GetByteCount(set.TotalLength);
            int validCount = Varint.GetByteCount(set.ValidLength);


            int instanceCount = 0;

            for (int i = 0; i < set.ValidObjects.Length; i++)
            {
                int    index = set.ValidObjects[i].Index;
                object obj   = set.ValidObjects[i].Object;

                ITypeDescriber describer = _TypeSet.Get(obj.GetType());

                instanceCount += Varint.GetByteCount(index);
                instanceCount += _TypeSet.Get().GetByteCount(obj.GetType());
                instanceCount += describer.GetByteCount(obj);
            }

            return(instanceCount + lenCount + validCount);
        }