Npgsql.WriteBuffer.WriteUInt16 C# (CSharp) Method

WriteUInt16() public method

public WriteUInt16 ( int i ) : void
i int
return void
        public void WriteUInt16(int i)
        {
            Contract.Requires(WriteSpaceLeft >= sizeof(ushort));
            _buf[_writePosition++] = (byte)(i >> 8);
            _buf[_writePosition++] = (byte)i;
        }

Usage Example

示例#1
0
        internal async Task WriteParse(string sql, string statementName, List <NpgsqlParameter> inputParameters, bool async)
        {
            Debug.Assert(statementName.All(c => c < 128));

            int queryByteLen;

            try
            {
                queryByteLen = TextEncoding.GetByteCount(sql);
            }
            catch (Exception e)
            {
                Break(e);
                throw;
            }

            if (WriteBuffer.WriteSpaceLeft < 1 + 4 + statementName.Length + 1)
            {
                await Flush(async);
            }

            var messageLength =
                sizeof(byte) +                        // Message code
                sizeof(int) +                         // Length
                statementName.Length +                // Statement name
                sizeof(byte) +                        // Null terminator for the statement name
                queryByteLen + sizeof(byte) +         // SQL query length plus null terminator
                sizeof(ushort) +                      // Number of parameters
                inputParameters.Count * sizeof(int);  // Parameter OIDs

            WriteBuffer.WriteByte(FrontendMessageCode.Parse);
            WriteBuffer.WriteInt32(messageLength - 1);
            WriteBuffer.WriteNullTerminatedString(statementName);

            await WriteBuffer.WriteString(sql, queryByteLen, async);

            if (WriteBuffer.WriteSpaceLeft < 1 + 2)
            {
                await Flush(async);
            }
            WriteBuffer.WriteByte(0); // Null terminator for the query
            WriteBuffer.WriteUInt16((ushort)inputParameters.Count);

            foreach (var p in inputParameters)
            {
                if (WriteBuffer.WriteSpaceLeft < 4)
                {
                    await Flush(async);
                }

                WriteBuffer.WriteInt32((int)p.Handler !.PostgresType.OID);
            }
        }
All Usage Examples Of Npgsql.WriteBuffer::WriteUInt16