Beispiel #1
0
        private static byte[] LoadZeroCompressed(BinaryReader reader)
        {
            var ret = new List<byte>();
            uint packedLen = reader.ReadSizeEx();
            long max = reader.BaseStream.Position + packedLen;
            while (reader.BaseStream.Position < max)
            {
                var opcode = new ZeroCompressOpcode(reader.ReadByte());

                if (opcode.FirstIsZero)
                {
                    for (int n = 0; n < (opcode.FirstLength+1); n++)
                        ret.Add(0x00);
                }
                else
                {
                    int bytes = (int)Math.Min(8 - opcode.FirstLength, max - reader.BaseStream.Position);
                    for (int n = 0; n < bytes; n++)
                        ret.Add(reader.ReadByte());
                }

                if (opcode.SecondIsZero)
                {
                    for (int n = 0; n < (opcode.SecondLength+1); n++)
                        ret.Add(0x00);
                }
                else
                {
                    int bytes = (int)Math.Min(8 - opcode.SecondLength, max - reader.BaseStream.Position);
                    for (int n = 0; n < bytes; n++)
                        ret.Add(reader.ReadByte());
                }
            }
            return ret.ToArray();
        }
Beispiel #2
0
        private static byte[] LoadZeroCompressed(BinaryReader reader)
        {
            var  ret       = new List <byte>();
            uint packedLen = reader.ReadSizeEx();
            long max       = reader.BaseStream.Position + packedLen;

            while (reader.BaseStream.Position < max)
            {
                var opcode = new ZeroCompressOpcode(reader.ReadByte());

                if (opcode.FirstIsZero)
                {
                    for (int n = 0; n < (opcode.FirstLength + 1); n++)
                    {
                        ret.Add(0x00);
                    }
                }
                else
                {
                    int bytes = (int)Math.Min(8 - opcode.FirstLength, max - reader.BaseStream.Position);
                    for (int n = 0; n < bytes; n++)
                    {
                        ret.Add(reader.ReadByte());
                    }
                }

                if (opcode.SecondIsZero)
                {
                    for (int n = 0; n < (opcode.SecondLength + 1); n++)
                    {
                        ret.Add(0x00);
                    }
                }
                else
                {
                    int bytes = (int)Math.Min(8 - opcode.SecondLength, max - reader.BaseStream.Position);
                    for (int n = 0; n < bytes; n++)
                    {
                        ret.Add(reader.ReadByte());
                    }
                }
            }
            return(ret.ToArray());
        }