public override void Load(ByteStream byteStream) { this.ParameterType = (IsupParameterType)byteStream.Read(); var len = byteStream.Read(); this.LoadParameterData(byteStream.Read(len)); }
public override void Load(ByteStream byteStream) { this.PointerToParameter = byteStream.Read(); this.PointerToOptionalParameter = byteStream.Read(); var parameterLength = byteStream.Read(); this.LoadParameterData(byteStream.Read(parameterLength)); }
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); } }
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()); }
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()); }
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); }
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); } }
// // Reading and writing // public OctetString(ByteStream queue) { int length = (int)readTag(queue); Bytes = new byte[length]; queue.Read(Bytes); }
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 }
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; } } }
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); }
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()); } } }
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); }
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(); } } }
// // 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); }
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); } }
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; } }
// // 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); } }
// // 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(); } }
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)); } }
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!"); }
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(); }
public override object ReadObject(ByteStream _TargetStream) { ushort len = (ushort)Converter.Converters[typeof(ushort)].ReadObject(_TargetStream); return System.Text.Encoding.ASCII.GetString(_TargetStream.Read(len)); }
public static byte[] getByteArray(this ByteStream stream, int count) { byte[] bytes = new byte[count]; stream.Read(bytes, 0, count); return bytes; }
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)); }
public static void Literal(ByteStream compressed, List <byte> decompressed, int length) { // Copy 'length' bytes directly to the decompressed stream. decompressed.AddRange(compressed.Read(length)); }
public override object ReadObject(ByteStream _TargetStream) { return _TargetStream.Read(); }
public override void Load(ByteStream byteStream) { this.LoadParameterData(byteStream.Read(this.parameterLength)); }
public override object ReadObject(ByteStream _TargetStream) { return BitConverter.ToInt32(_TargetStream.Read(4), 0); }