Exemplo n.º 1
0
        public static IEnumerable <T> ReadCollection <T>(IBinarySerialization <T> serialization, long offset = 0)
        {
            List <T> collection = new List <T>();
            int      count      = ReadInt32(offset);

            T   obj    = default(T);
            int length = 0;

            byte[] bytes = null;

            ReadAction <T> readAction = (binaryReader) =>
            {
                obj    = default(T);
                length = binaryReader.ReadInt32();
                bytes  = binaryReader.ReadBytes(length);
                obj    = serialization.Deserialize(bytes);
                return(obj);
            };

            long currentOffset = offset + TypeSizes.SIZE_INT;

            for (int k = 0; k < count; k++)
            {
                ExecuteRead <T>(readAction, currentOffset);
                collection.Add(obj);
                currentOffset = currentOffset + TypeSizes.SIZE_INT + length;
            }

            return(collection);
        }
Exemplo n.º 2
0
        public static T Read <T>(IBinarySerialization <T> serialization, long offset = 0)
        {
            ReadAction <T> readAction = (binaryReader) =>
            {
                T      obj    = default(T);
                int    length = binaryReader.ReadInt32();
                byte[] bytes  = binaryReader.ReadBytes(length);
                obj = serialization.Deserialize(bytes);
                return(obj);
            };

            return(ExecuteRead <T>(readAction, offset));
        }