public override void WriteToStream(Stream outputStream) { if (_messageLength == 0) { _messageLength = 4 + // Message length (32 bits) _bPortalName.Length + 1 + // Portal name + null terminator _bPreparedStatementName.Length + 1 + // Statement name + null terminator 2 + // Parameter format code array length (16 bits) _parameterFormatCodes.Length * 2 + // Parameter format code array (16 bits per code) 2; // Parameter va;ue array length (16 bits) if (_parameterValues != null) { for (int i = 0; i < _parameterValues.Length; i++) { _messageLength += 4; // Parameter value length (32 bits) if (_parameterValues[i] != null) { _messageLength += _parameterValues[i].Length; // Parameter value } } } _messageLength += 2 + // Result format code array length (16 bits) _resultFormatCodes.Length * 2; // Result format code array (16 bits per code) } outputStream .WriteBytes((byte)FrontEndMessageCode.Bind) .WriteInt32(_messageLength) .WriteBytesNullTerminated(_bPortalName) .WriteBytesNullTerminated(_bPreparedStatementName) .WriteInt16((Int16)_parameterFormatCodes.Length); foreach (short code in _parameterFormatCodes) { PGUtil.WriteInt16(outputStream, code); } if (_parameterValues != null) { PGUtil.WriteInt16(outputStream, (Int16)_parameterValues.Length); for (int i = 0; i < _parameterValues.Length; i++) { Byte[] parameterValue = _parameterValues[i]; if (parameterValue == null) { PGUtil.WriteInt32(outputStream, -1); } else { outputStream .WriteInt32(parameterValue.Length) .WriteBytes(parameterValue); } } } else { PGUtil.WriteInt16(outputStream, 0); } PGUtil.WriteInt16(outputStream, (Int16)_resultFormatCodes.Length); foreach (short code in _resultFormatCodes) { PGUtil.WriteInt16(outputStream, code); } }