public static byte[] CreateMessage(string topic, byte[] data, int offset, int length, UTF8Encoding encoder) { byte[] topicBytes = encoder.GetBytes(topic); MessageHeader header = new MessageHeader(topicBytes.Length, length); int totalSize = HEADER_SIZE + header.TotalSize; byte[] allData = new byte[totalSize]; header.WriteToBuffer(allData); Array.Copy(topicBytes, 0, allData, HEADER_SIZE, topicBytes.Length); Array.Copy(data, offset, allData, HEADER_SIZE + topicBytes.Length, length); return allData; }
public void ParseBytes(EndPoint endpoint, byte[] buffer, int offset, int received) { _endPoint = EndPoint; _buffer = buffer; _offset = offset; //fixed (byte* pArray = buffer) //{ while (_offset < received) { _topic = null; _object = null; //byte* pHeader = (pArray + _offset); _currentHeader = new MessageHeader( BitConverter.ToInt32(buffer, _offset+4), BitConverter.ToInt32(buffer, _offset)); int msgSize = TopicPublisher.HEADER_SIZE + _currentHeader.TopicSize + _currentHeader.BodySize; _listener.OnMessage(this); _offset += msgSize; } //} }