public override EventPackageInfo ResolvePackage(IBufferStream bufferStream) { //log4j.Debug("bufferStream.Length: " + bufferStream.Length); //log4j.Debug("headerSize: " + this.HeaderSize); //log4j.Debug("bodySize: " + ((int)bufferStream.Length - this.HeaderSize)); //int key1 = bufferStream.Skip(4).ReadByte(); //int key2 = bufferStream.ReadByte(); //int key = key2 << 8 | key1; //int subKey1 = bufferStream.ReadByte(); //int subKey2 = bufferStream.ReadByte(); //int subKey = subKey2 << 8 | subKey1; EventPackageInfo ev = new EventPackageInfo(0, 0, ""); try { int key = bufferStream.Skip(4).ReadUInt16(true); // why read little indian?? int subKey = bufferStream.ReadUInt16(true); //log4j.Debug(string.Format("key: {0}, subKey: {1}", key, subKey)); string body = bufferStream.ReadString((int)bufferStream.Length - this.HeaderSize, Encoding.UTF8); ev = new EventPackageInfo(key, subKey, body); } catch (Exception ex) { log4j.Error("ResolvePackage: ", ex); } return(ev); }
protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length) { int val1 = bufferStream.ReadUInt16(true); int dataSize = bufferStream.ReadUInt16(true); // int val3 = bufferStream.ReadUInt16(true); // int val4 = bufferStream.ReadUInt16(true); dataSize = dataSize - this.HeaderSize; //log4j.Debug("val: " + val); //if (dataSize > 2000 || val1 != 17408) //{ // //log4j.Debug("val > 2000 : " + val); // log4j.Debug("incorrect header 17408 or size > 2000"); // dataSize = 0; //} return(dataSize); }
protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length) { bufferStream.Skip(4); return(bufferStream.ReadUInt16()); }
private int GetPayloadLength(IBufferStream bufferStream, int length) { if (length == 2) { var flag = bufferStream.ReadByte(); m_Final = (FINAL_FLAG & flag) == flag; m_OpCode = (sbyte)(flag & 0x08); // one byte playload length var playloadLen = (int)bufferStream.ReadByte(); //the highest bit is mask indicator m_Masked = playloadLen > 128; // remove the mask byte playloadLen = playloadLen % 128; // no extend playload length if (playloadLen < 126) { if (!m_Masked) { return(playloadLen); } // masking-key: 4 bytes return(playloadLen + 4); } // playload length takes 2 bytes if (playloadLen == 126) { ResetSize(4); return(-1); } else// playload length takes 8 bytes { ResetSize(10); return(-1); } } else if (length == 4) { bufferStream.Skip(2); // 2 bytes var playloadLen = bufferStream.ReadUInt16(); if (m_Masked) // add mask key's length { playloadLen += 4; } return(playloadLen); } else // length = 8 { bufferStream.Skip(2); // 8 bytes var playloadLen = bufferStream.ReadUInt64(); if (m_Masked) // add mask key's length { playloadLen += 4; } return((int)playloadLen); } }
protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length) { int bodyLength = bufferStream.ReadUInt16(); return(bodyLength); }