public SPWF04SxCommand Finalize(SPWF04SxCommandIds cmdId, byte[] rawData, int rawDataOffset, int rawDataCount) { if (rawData == null && rawDataCount != 0) { throw new ArgumentException(); } if (rawDataOffset < 0) { throw new ArgumentOutOfRangeException(); } if (rawDataCount < 0) { throw new ArgumentOutOfRangeException(); } if (rawData != null && rawDataOffset + rawDataCount > rawData.Length) { throw new ArgumentOutOfRangeException(); } var required = 4 + this.parameterCount; for (var i = 0; i < this.parameterCount; i++) { var p = this.parameters[i]; required += p != null ? p.Length : 0; } this.writeHeader.EnsureSize(required, false); var idx = 0; var buf = this.writeHeader.Data; buf[idx++] = 0x00; buf[idx++] = 0x00; buf[idx++] = (byte)cmdId; buf[idx++] = (byte)this.parameterCount; for (var i = 0; i < this.parameterCount; i++) { var p = this.parameters[i]; var pLen = p != null ? p.Length : 0; buf[idx++] = (byte)pLen; if (!string.IsNullOrEmpty(p)) { Encoding.UTF8.GetBytes(p, 0, pLen, buf, idx); } idx += pLen; } var len = idx + rawDataCount - 2; buf[0] = (byte)((len >> 8) & 0xFF); buf[1] = (byte)((len >> 0) & 0xFF); this.writePayload = rawData; this.writePayloadOffset = rawDataOffset; this.writePayloadLength = rawDataCount; this.writeHeaderLength = idx; return(this); }
public SPWF04SxCommand Finalize(SPWF04SxCommandIds cmdId) => this.Finalize(cmdId, null, 0, 0);