Beispiel #1
0
        int ITypeDescriber.GetByteCount(object instance)
        {
            try
            {
                var validFields = _Fields.Select(
                    (field, index) => new
                {
                    field,
                    index
                }).Where(validField => object.Equals(_GetDescriber(validField.field).Default, validField.field.GetValue(instance)) == false).ToArray();


                var validCount = Varint.GetByteCount(validFields.Length);
                int count      = 0;
                for (int i = 0; i < validFields.Length; i++)
                {
                    var validField     = validFields[i];
                    var value          = validField.field.GetValue(instance);
                    var valueType      = value.GetType();
                    var valueTypeCount = _TypeSet.Get().GetByteCount(valueType);
                    var describer      = _TypeSet.Get(valueType);
                    var byteCount      = describer.GetByteCount(value);

                    var indexCount = Varint.GetByteCount(validField.index);
                    count += byteCount + indexCount + valueTypeCount;
                }
                return(count + validCount);
            }
            catch (Exception ex)
            {
                throw new DescriberException(typeof(ClassDescriber), _Type, "GetByteCount", ex);
            }
        }
Beispiel #2
0
        int IKeyDescriber.GetByteCount(Type type)
        {
            int id      = _Get(type);
            int idCount = Varint.GetByteCount(id);

            return(idCount);
        }
Beispiel #3
0
        int ITypeDescriber.GetByteCount(object instance)
        {
            var set = _GetSet(instance);


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


            var instanceCount = 0;

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

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

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

            return(instanceCount + lenCount + validCount);
        }
Beispiel #4
0
        private byte[] _NullBuffer()
        {
            var idCount = Varint.GetByteCount(0);
            var buffer  = new byte[idCount];

            Varint.NumberToBuffer(buffer, 0, 0);
            return(buffer);
        }
Beispiel #5
0
 public static int GetByteCount(int value)
 {
     return(Varint.GetByteCount((ulong)value));
 }