public void Encode(object obj, Stream stream) { var msg = obj as Datagram; if (msg == null) { return; } int start = (int)stream.Position; int headerStart = start + RemotingHeader.LengthFieldLen; stream.Position = headerStart; byte[] buffer = new byte[4]; EncodeHeader(msg.Header, buffer, stream); int headerSize = (int)stream.Position - headerStart; msg.WriteBody(stream); int end = (int)stream.Position; int total = end - start - RemotingHeader.TotalSizeLen; stream.Position = start; ByteBufHelper.WriteInt32(total, buffer, stream); ByteBufHelper.WriteInt16((short)headerSize, buffer, stream); stream.Position = end; }
private void EncodeHeader(RemotingHeader header, byte[] buffer, Stream stream) { ByteBufHelper.WriteInt32(RemotingHeader.QmqMagicCode, buffer, stream); ByteBufHelper.WriteInt16(header.Code, buffer, stream); ByteBufHelper.WriteInt16(header.Version, buffer, stream); ByteBufHelper.WriteInt32(header.Opaque, buffer, stream); ByteBufHelper.WriteInt32(header.Flag, buffer, stream); ByteBufHelper.WriteInt16(header.RequestCode, buffer, stream); }
public void Write(Stream output) { var start = output.Position; output.Position += 2; short size = 4; byte[] lenBuffer = new byte[2]; output.Write(SubjectLen, 0, 2); output.Write(Subject, 0, Subject.Length); ByteBufHelper.WriteString(_request.Subject, lenBuffer, output); output.Write(ClientTypeCodeLen, 0, 2); output.Write(ClientTypeCode, 0, ClientTypeCode.Length); ByteBufHelper.WriteString(_request.ClientType.ToString(), lenBuffer, output); output.Write(AppCodeLen, 0, 2); output.Write(AppCode, 0, AppCode.Length); ByteBufHelper.WriteInt16((short)_request.AppCode.Length, lenBuffer, output); output.Write(_request.AppCode, 0, _request.AppCode.Length); if (!string.IsNullOrEmpty(_request.ClientId)) { output.Write(ClientIdLen, 0, 2); output.Write(ClientId, 0, ClientId.Length); ByteBufHelper.WriteString(_request.ClientId, lenBuffer, output); size += 1; } if (!string.IsNullOrEmpty(_request.ConsumerGroup)) { output.Write(ConsumerGroupLen, 0, 2); output.Write(ConsumerGroup, 0, ConsumerGroup.Length); ByteBufHelper.WriteString(_request.ConsumerGroup, lenBuffer, output); size += 1; } output.Write(RequestTypeLen, 0, 2); output.Write(RequestType, 0, RequestType.Length); ByteBufHelper.WriteString(_request.RequestType.ToString(), lenBuffer, output); long end = output.Position; output.Position = start; ByteBufHelper.WriteInt16(size, lenBuffer, output); output.Position = end; }
private void WriteTags(PullMessageRequest request, byte[] buffer, Stream output) { ByteBufHelper.WriteInt16(_request.TagType, buffer, output); var tags = request.Tags; if (tags == null || tags.Length == 0) { ByteBufHelper.WriteByte((byte)0, output); return; } ByteBufHelper.WriteByte((byte)tags.Length, output); foreach (var tag in _request.Tags) { ByteBufHelper.WriteString(tag, buffer, output); } }