Read() public method

public Read ( int count ) : byte[]
count int
return byte[]
Ejemplo n.º 1
0
        public override void Load(ByteStream byteStream)
        {
            this.ParameterType = (IsupParameterType)byteStream.Read();
            var len = byteStream.Read();

            this.LoadParameterData(byteStream.Read(len));
        }
Ejemplo n.º 2
0
        public override void Load(ByteStream byteStream)
        {
            this.PointerToParameter         = byteStream.Read();
            this.PointerToOptionalParameter = byteStream.Read();

            var parameterLength = byteStream.Read();

            this.LoadParameterData(byteStream.Read(parameterLength));
        }
Ejemplo n.º 3
0
        protected void LoadData(ByteStream bs)
        {
            foreach (var h in this.GetOptionalHeaders())
            {
                h.Load(bs);
            }

            var required = this.GetRequiredParameter();

            if (required != null)
            {
                required.Load(bs);
            }

            while (true)
            {
                if (required == null)
                {
                    var startOfOptionalParameter = bs.Read();

                    if (startOfOptionalParameter == 0)
                    {
                        break;
                    }
                }

                var parameterType = (IsupParameterType)bs.Read();
                if (parameterType == IsupParameterType.EndOfOptionalParameters)
                {
                    break;
                }

                int           len  = bs.Read();
                var           data = bs.Read(len);
                IsupParameter p;
                switch (parameterType)
                {
                case IsupParameterType.CallingPartyNumber:
                case IsupParameterType.RedirectingNumber:
                case IsupParameterType.OriginalCalledNumber:
                    p = new IsupPhoneNumberParameter(parameterType);
                    break;

                case IsupParameterType.RedirectionInfo:
                    p = new RedirectInfo();
                    break;

                default:
                    p = new OptionalIsupParameter(parameterType, len);
                    break;
                }

                p.LoadParameterData(data);

                this.AddOptionalParameter(p);
            }
        }
Ejemplo n.º 4
0
        int GetPackHeaderSize()
        {
            ByteStream cStream    = new ByteStream();
            int        headerType = 0;
            short      size       = 0;

            cStream.Read(out headerType);
            cStream.Read(out size);
            cStream.IgroneAlignBytes();
            return(cStream.GetNumberOfCurtBytes());
        }
Ejemplo n.º 5
0
        public override int ReadStreamToHeader(GamePackHeader header, ByteStream readStream, bool isNetToHost)
        {
            int headerType = 0;

            readStream.Read(out headerType);
            header.type = (GamePackType)headerType;

            readStream.Read(out header.dataSize);
            readStream.ReadAlignBytes();
            return(readStream.GetNumberOfCurtBytes());
        }
Ejemplo n.º 6
0
        int GetPackDataLength(DePacketor dePacketor, byte[] pack, int offset, int packLen, out int realPackHeadLen)
        {
            int   type;
            short dataSize;

            ByteStream readStream = new ByteStream(pack, offset, packLen);

            readStream.Read(out type);
            readStream.Read(out dataSize);
            readStream.ReadAlignBytes();

            realPackHeadLen = readStream.GetNumberOfCurtBytes();

            return(dataSize);
        }
Ejemplo n.º 7
0
    public RbyTileset(Rby game, byte id, ByteStream data)
    {
        Game = game;
        Id   = id;

        Bank             = data.u8();
        BlockPointer     = data.u16le();
        GfxPointer       = data.u16le();
        CollisionPointer = data.u16le();
        CounterTiles     = data.Read(3);
        GrassTile        = data.u8();
        data.Seek(1);

        TilePairCollisionsLand  = new List <RbyTilePairCollision>();
        TilePairCollisionsWater = new List <RbyTilePairCollision>();

        LandPermissions = new PermissionSet();
        LandPermissions.AddRange(game.ROM.From((game is Yellow ? 0x01 : 0x00) << 16 | CollisionPointer).Until(0xff));
        WaterPermissions = new PermissionSet();
        WaterPermissions.Add(0x14);
        WaterPermissions.Add(0x32);
        if (id == 14)
        {
            WaterPermissions.Add(0x48);
        }
    }
Ejemplo n.º 8
0
        //
        // Reading and writing
        //
        public OctetString(ByteStream queue)
        {
            int length = (int)readTag(queue);

            Bytes = new byte[length];
            queue.Read(Bytes);
        }
Ejemplo n.º 9
0
 public GscSpecies(Gsc game, ByteStream data, ByteStream name)   // Names are padded to 10 length using terminator characters.
 {
     Game               = game;
     Name               = game.Charmap.Decode(name.Read(10));
     Id                 = data.u8();
     BaseHP             = data.u8();
     BaseAttack         = data.u8();
     BaseDefense        = data.u8();
     BaseSpeed          = data.u8();
     BaseSpecialAttack  = data.u8();
     BaseSpecialDefense = data.u8();
     Type1              = (GscType)data.u8();
     Type2              = (GscType)data.u8();
     CatchRate          = data.u8();
     BaseExp            = data.u8();
     Item1              = data.u8();
     Item2              = data.u8();
     GenderRatio        = data.u8();
     Unknown1           = data.u8();
     HatchCycles        = data.u8();
     Unknown2           = data.u8();
     FrontSpriteWidth   = data.Nybble();
     FrontSpriteHeight  = data.Nybble();
     data.Seek(4); // 4 unused bytes
     GrowthRate = (GrowthRate)data.u8();
     EggGroup1  = (GscEggGroup)data.Nybble();
     EggGroup2  = (GscEggGroup)data.Nybble();
     data.Seek(8); // TODO: HMs/TMs
 }
Ejemplo n.º 10
0
    public static void Decode(ByteStream data, Bitmap dest)
    {
        PNGHeader header = data.Struct <PNGHeader>(true);

        Debug.Assert(header.Signature == PNGSignature, "Specified file was not a PNG file.");

        ByteStream idatStream = new ByteStream();

        while (true)
        {
            PNGChunkHeader chunkHeader = data.Struct <PNGChunkHeader>(true);
            string         chunkType   = Encoding.ASCII.GetString(chunkHeader.Type, 4);
            byte[]         chunkBytes  = data.Read(chunkHeader.Length);
            ByteStream     chunkData   = new ByteStream(chunkBytes);
            PNGChunkFooter chunkFooter = data.Struct <PNGChunkFooter>(true);

            Debug.Assert(Crc32(chunkHeader.ToBytes().Concat(chunkBytes).ToArray(), 4) == chunkFooter.CRC, chunkType + " chunk's CRC mismatched!");

            switch (chunkType)
            {
            case "IHDR":
                PNGIHDR ihdr = chunkData.Struct <PNGIHDR>(true);
                Debug.Assert(ihdr.BitDepth == 8 && ihdr.ColorType == 6 && ihdr.CompressionMethod == 0 &&
                             ihdr.FilterMethod == 0 && ihdr.InterlaceMethod == 0, "The specified PNG file uses an unsupported format.");
                dest.Width  = ihdr.Width;
                dest.Height = ihdr.Height;
                dest.Pixels = new byte[ihdr.Width * ihdr.Height * 4];
                break;

            case "IDAT":
                idatStream.Write(chunkData.Read(chunkHeader.Length));
                break;

            case "IEND":
                idatStream.Seek(0, SeekOrigin.Begin);
                PNGIDATHeader idatHeader = idatStream.Struct <PNGIDATHeader>(true);
                byte[]        idatData;
                PNGIDATFooter idatFooter;
                using (MemoryStream target = new MemoryStream())
                    using (DeflateStream decompressionStream = new DeflateStream(idatStream, CompressionMode.Decompress)) {
                        decompressionStream.CopyTo(target);
                        idatData = target.ToArray();
                        idatStream.Seek(-4);
                        idatFooter = idatStream.Struct <PNGIDATFooter>(true);
                    }

                Debug.Assert(idatFooter.CheckValue == Alder32(idatData), "IDAT chunk compression check value mismatch!");
                int scanlineSize = dest.Width * 4;
                for (int scanline = 0; scanline < dest.Height; scanline++)
                {
                    int offset = scanline * scanlineSize;
                    Array.Copy(idatData, offset + scanline + 1, dest.Pixels, offset, scanlineSize);
                }
                return;
            }
        }
    }
Ejemplo n.º 11
0
        void SetDataLengthToPackHead(byte[] pack, int dataSize)
        {
            int   headerType = 0;
            short size       = (short)dataSize;

            ByteStream readStream = new ByteStream(pack);

            readStream.Read(out headerType);
            readStream.Write(size);
        }
Ejemplo n.º 12
0
        public void TestByteStream()
        {
            byte[] data = new byte[1024];
            for (int i = 0; i < 1024; i++)
            {
                data[i] = (byte)(i % 256);
            }

            ByteStream bStream = new ByteStream(data);

            byte[] buffer = new byte[512];
            bStream.Read(buffer, 0, 512);
            for (int bufferIndex = 0; bufferIndex < buffer.Length; bufferIndex++)
            {
                if (buffer[bufferIndex] != bufferIndex % 256)
                {
                    throw new Exception("Expecting " + (bufferIndex).ToString());
                }
            }

            bStream.Seek(0, SeekOrigin.Begin);
            if (bStream.ReadByte() != 0)
            {
                throw new Exception("Expecting expected 0");
            }

            if (bStream.ReadByte() != 1)
            {
                throw new Exception("Expecting expected 1");
            }

            bStream.Seek(510, SeekOrigin.Current);
            bStream.Read(buffer, 0, 512);
            for (int i = 0; i < buffer.Length; i++)
            {
                if (buffer[i] != (i + 512) % 256)
                {
                    throw new Exception("Expecting " + (i + 512).ToString());
                }
            }
        }
Ejemplo n.º 13
0
    public static void Decode(ByteStream data, Bitmap dest)
    {
        BMPHeader header = data.Struct <BMPHeader>();

        Debug.Assert(header.Signature == BMPSignature, "Specified file was not a BMP file.");
        Debug.Assert(header.Size == InfoHeaderSize, "The BMP file contains an unsupported info header.");
        Debug.Assert(header.Compression == 0, "Only uncompressed BMP files are supported.");
        Debug.Assert(header.BitsPerPixel == 32, "Only 32-bit colors are supported.");
        Debug.Assert(header.FileSize - header.DataOffset == header.Width * header.Height * 4, "The BMP file is missing pixel data.");
        dest.Width  = header.Width;
        dest.Height = header.Height;
        dest.Pixels = RemapData(data.Read(dest.Width * dest.Height * 4), dest.Width, dest.Height);
    }
Ejemplo n.º 14
0
        public NPDU(ByteStream source)
        {
            version = source.ReadByte();
            control = new NLPCI(source.ReadByte());

            if (control.IsDestinationSpecific)
            {
                destinationNetworkAddress       = source.popU2B();
                destinationMacLyerAddressLength = source.popU1B();
                if (destinationMacLyerAddressLength > 0)
                {
                    destinationAddress = new byte[destinationMacLyerAddressLength];
                    source.Read(destinationAddress);
                }
            }

            if (control.IsSourceSpecific)
            {
                // TODO Check address length
                sourceNetworkAddress       = source.popU2B();
                sourceMacLyerAddressLength = source.popU1B();
                sourceAddress = new byte[sourceMacLyerAddressLength];
                source.Read(destinationAddress);
            }

            if (control.IsDestinationSpecific)
            {
                hopCount = source.popU1B();
            }

            if (control.IsNetworkLayerMessage)
            {
                messageType = source.popU1B();
                if (messageType >= 80)
                {
                    vendorId = source.popU2B();
                }
            }
        }
Ejemplo n.º 15
0
        //
        // Reading and writing
        //
        public CharacterString(ByteStream queue)
        {
            int length = (int)readTag(queue);

            //byte enc = queue.ReadByte();
            //Encoding = Encodings.ANSI_X3_4;
            Encoding = (Encodings)queue.ReadByte();
            validateEncoding();

            byte[] bytes = new byte[length - 1];
            queue.Read(bytes);

            Value = decode(Encoding, bytes);
        }
Ejemplo n.º 16
0
        public BVLC(ByteStream source)
        {
            // Initial parsing of IP message.
            // BACnet/IP
            type = (BVLCType)source.ReadByte();
            if (type != BVLCType.BACnetIP_AnnexJ) // NO BVLC !!
            {
                throw new MessageValidationAssertionException("Protocol id is not BACnet/IP (0x81)");
            }

            function = (BVLCFunction)source.ReadByte();
            if (function != BVLCFunction.OriginalUnicastNPDU &&
                function != BVLCFunction.OriginalBroadcastNPDU &&
                function != BVLCFunction.ForwardedNPDU &&
                function != 0x0)
            {
                throw new MessageValidationAssertionException("Function is not unicast, broadcast, forward"
                                                              + " or foreign device reg anwser (0xa, 0xb, 0x4 or 0x0)");
            }

            length = source.ReadShort();
            if (length != source.Length /* + 4*/)
            {
                throw new MessageValidationAssertionException("Length field does not match data: given=" + length
                                                              + ", expected=" + (source.Length /* + 4*/));
            }

            // answer to foreign device registration
            if (function == 0x0)
            {
                int regResult = source.ReadShort();
                if (regResult != 0)
                {
                    Debug.Print("Foreign device registration not successful! result: " + regResult);
                }

                // not APDU received, bail
                //return null; // TODO Test
            }

            if (function == BVLCFunction.ForwardedNPDU)
            {
                // A forward. Use the address/port as the link service address.
                byte[] addr = new byte[6];
                source.Read(addr);
                var linkService = new OctetString(addr);
            }
        }
Ejemplo n.º 17
0
    void ParseMsg()
    {
        int msgBodySize = -1;

        while (_receiveBuffer.bytesAvailable >= 6)//head(2B) + uniq(2B) + frame(1B) + way(1B)
        {
            //还没读取包头:协议体的长度
            if (msgBodySize < 0)
            {
                msgBodySize = _receiveBuffer.ReadUShort();
            }

            //无法凑成一条完整协议包:结束并回退到包头
            if (_receiveBuffer.bytesAvailable < msgBodySize)
            {
                _receiveBuffer.position -= 2;
                break;
            }

            byte[] bytes = new byte[msgBodySize];
            _receiveBuffer.Read(bytes, 0, msgBodySize);
            _recvQueue.Enqueue(new ByteStream(bytes));
            //if(msgBodySize > 25)
            //{
            //    System.Text.StringBuilder sb = new System.Text.StringBuilder();
            //    sb.Append(bytes[0]);
            //    sb.Append("_");
            //    sb.Append(bytes[1]);
            //    sb.Append(" 协议 -> ");
            //    for (int i = 2; i < msgBodySize;++i )
            //        sb.Append(bytes[i]);
            //    UnityEngine.Debug.Log(sb.ToString());
            //}

            msgBodySize = -1;
        }

        //剩余不足拼成一条完整协议包的内容,前移到起始位置
        if (_receiveBuffer.position != 0)
        {
            int numLeft = _receiveBuffer.bytesAvailable;
            Buffer.BlockCopy(_receiveBuffer.buffer, _receiveBuffer.position,
                             _receiveBuffer.buffer, 0, numLeft);

            _receiveBuffer.position = 0;
            _receiveBuffer.length   = numLeft;
        }
    }
Ejemplo n.º 18
0
        //
        // Reading and writing
        //
        public BitString(ByteStream queue)
        {
            int length    = (int)readTag(queue) - 1;
            int remainder = queue.popU1B();

            if (length == 0)
            {
                Value = new bool[0];
            }
            else
            {
                byte[] data = new byte[length];
                queue.Read(data);
                Value = BACnetUtils.convertToBooleans(data, length * 8 - remainder);
            }
        }
Ejemplo n.º 19
0
        //
        // Reading and writing
        //
        public SignedInteger(ByteStream queue)
        {
            // Read the data length value.
            int length = (int)readTag(queue);

            byte[] bytes = new byte[length];
            queue.Read(bytes);

            if (length < 5)
            {
                Value = BitConverter.ToInt32(bytes, 0);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 20
0
    static int Read(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                ByteStream obj  = (ByteStream)ToLua.CheckObject <ByteStream>(L, 1);
                byte[]     arg0 = ToLua.CheckByteBuffer(L, 2);
                obj.Read(arg0);
                return(0);
            }
            else if (count == 3)
            {
                ByteStream obj  = (ByteStream)ToLua.CheckObject <ByteStream>(L, 1);
                byte[]     arg0 = ToLua.CheckByteBuffer(L, 2);
                int        arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                obj.Read(arg0, arg1);
                return(0);
            }
            else if (count == 4)
            {
                ByteStream obj  = (ByteStream)ToLua.CheckObject <ByteStream>(L, 1);
                byte[]     arg0 = ToLua.CheckByteBuffer(L, 2);
                int        arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                int        arg2 = (int)LuaDLL.luaL_checknumber(L, 4);
                obj.Read(arg0, arg1, arg2);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: ByteStream.Read"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Ejemplo n.º 21
0
    void ExtractMIDI(ByteStream stream)
    {
        if (stream.ReadString(4) != "MIDI") {
            throw new InvalidDataException("Not a GMD file!");
        }
        stream.Skip(4);

        string type;
        while ((type = GetChunkType(stream)) != null) {
            if (type == "MThd") {
                long size = stream.Length - stream.Position;
                _midiData = stream.Read((int)size);
                return;
            }

            if (!SkipChunk(stream)) {
                break;
            }
        }

        throw new InvalidDataException("Could not locate midi track header!");
    }
Ejemplo n.º 22
0
        public static IsupBody Load(ByteStream bs)
        {
            var type = (IsupMessageType)bs.Read();

            switch (type)
            {
            case IsupMessageType.IAM:
                return(new IsupInitialAddress(bs));

            case IsupMessageType.AddressComplete:
                return(new IsupAddressComplete(bs));

            case IsupMessageType.CallProgress:
                return(new IsupCallProgress(bs));

            case IsupMessageType.Answer:
            case IsupMessageType.Release:
                // TODO: implement ANM
                return(null);
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 23
0
 public override object ReadObject(ByteStream _TargetStream)
 {
     ushort len = (ushort)Converter.Converters[typeof(ushort)].ReadObject(_TargetStream);
     return System.Text.Encoding.ASCII.GetString(_TargetStream.Read(len));
 }
Ejemplo n.º 24
0
 public static byte[] getByteArray(this ByteStream stream, int count) {
     byte[] bytes = new byte[count];
     stream.Read(bytes, 0, count);
     return bytes;
 }
Ejemplo n.º 25
0
 public override void Load(ByteStream byteStream)
 {
     this.Indicator = (EventIndicator)byteStream.Read();
     this.PointerToOptionalParameter = byteStream.Read();
 }
 public override object ReadObject(ByteStream _TargetStream)
 {
     ushort length = (ushort)Converter.Converters[typeof(ushort)].ReadObject(_TargetStream);
     return new ByteStream(_TargetStream.Read(length));
 }
Ejemplo n.º 27
0
 public static void Literal(ByteStream compressed, List <byte> decompressed, int length)
 {
     // Copy 'length' bytes directly to the decompressed stream.
     decompressed.AddRange(compressed.Read(length));
 }
Ejemplo n.º 28
0
 public override object ReadObject(ByteStream _TargetStream)
 {
     return _TargetStream.Read();
 }
Ejemplo n.º 29
0
 public override void Load(ByteStream byteStream)
 {
     this.LoadParameterData(byteStream.Read(this.parameterLength));
 }
Ejemplo n.º 30
0
 public override object ReadObject(ByteStream _TargetStream)
 {
     return BitConverter.ToInt32(_TargetStream.Read(4), 0);
 }