internal void WriteByteArray(Byte[] b, int len, int offsetBuffer, TdsParserStateObject stateObj) { int offset = offsetBuffer; while (len > 0) { if ((stateObj._outBytesUsed + len) > stateObj._outBuff.Length) { int remainder = stateObj._outBuff.Length - stateObj._outBytesUsed; Buffer.BlockCopy(b, offset, stateObj._outBuff, stateObj._outBytesUsed, remainder); offset += remainder; stateObj._outBytesUsed += remainder; if (stateObj._outBytesUsed == stateObj._outBuff.Length) { stateObj.WritePacket(0); } len -= remainder; } else { Buffer.BlockCopy(b, offset, stateObj._outBuff, stateObj._outBytesUsed, len); stateObj._outBytesUsed += len; break; } } }
internal void WriteByte(byte b, TdsParserStateObject stateObj) { if (stateObj._outBytesUsed == stateObj._outBuff.Length) { stateObj.WritePacket(0); } stateObj._outBuff[stateObj._outBytesUsed++] = b; }
internal void WriteShort(int v, TdsParserStateObject stateObj) { if ((stateObj._outBytesUsed + 2) > stateObj._outBuff.Length) { WriteByte((byte)(v & 0xff), stateObj); WriteByte((byte)((v >> 8) & 0xff), stateObj); } else { stateObj._outBuff[stateObj._outBytesUsed++] = (byte)(v & 0xFF); stateObj._outBuff[stateObj._outBytesUsed++] = (byte)((v >> 8) & 0xFF); } }
internal void WriteString(string s, int length, int offset, TdsParserStateObject stateObj) { int cBytes = 2 * length; if (cBytes < (stateObj._outBuff.Length - stateObj._outBytesUsed)) { CopyStringToBytes(s, offset, stateObj._outBuff, stateObj._outBytesUsed, length); stateObj._outBytesUsed += cBytes; } else { if (stateObj._bTmp == null || stateObj._bTmp.Length < cBytes) { stateObj._bTmp = new byte[cBytes]; } CopyStringToBytes(s, offset, stateObj._bTmp, 0, length); WriteByteArray(stateObj._bTmp, cBytes, 0, stateObj); } }
private void WriteString(string s, TdsParserStateObject stateObj) { WriteString(s, s.Length, 0, stateObj); }
internal void WriteInt(int v, TdsParserStateObject stateObj) { WriteByteArray(BitConverter.GetBytes(v), 4, 0, stateObj); }