public override async Task Write(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
        {
            Debug.Assert(_resolvedType != null);
            Debug.Assert(_members != null);

            if (buf.WriteSpaceLeft < 4)
            {
                await buf.Flush(async);
            }
            buf.WriteInt32(_members.Count);

            foreach (var fieldDescriptor in _members)
            {
                var fieldHandler = fieldDescriptor.Handler;
                var fieldValue   = fieldDescriptor.Getter(value);

                if (buf.WriteSpaceLeft < 4)
                {
                    await buf.Flush(async);
                }

                buf.WriteUInt32(fieldDescriptor.OID);
                await fieldHandler.WriteObjectWithLength(fieldValue, buf, lengthCache, null, async);
            }
        }
Esempio n. 2
0
        internal PgServerMock WriteRowDescription(params FieldDescription[] fields)
        {
            CheckDisposed();

            _writeBuffer.WriteByte((byte)BackendMessageCode.RowDescription);
            _writeBuffer.WriteInt32(4 + 2 + fields.Sum(f => Encoding.GetByteCount(f.Name) + 1 + 18));
            _writeBuffer.WriteInt16(fields.Length);

            foreach (var field in fields)
            {
                _writeBuffer.WriteNullTerminatedString(field.Name);
                _writeBuffer.WriteUInt32(field.TableOID);
                _writeBuffer.WriteInt16(field.ColumnAttributeNumber);
                _writeBuffer.WriteUInt32(field.TypeOID);
                _writeBuffer.WriteInt16(field.TypeSize);
                _writeBuffer.WriteInt32(field.TypeModifier);
                _writeBuffer.WriteInt16((short)field.FormatCode);
            }

            return(this);
        }
Esempio n. 3
0
        public override async Task Write(TComposite composite, NpgsqlWriteBuffer buffer, NpgsqlLengthCache?lengthCache, bool async, CancellationToken cancellationToken = default)
        {
            if (_get == null)
            {
                ThrowHelper.ThrowInvalidOperationException_NoPropertyGetter(typeof(TComposite), MemberInfo);
            }

            if (buffer.WriteSpaceLeft < sizeof(int))
            {
                await buffer.Flush(async, cancellationToken);
            }

            buffer.WriteUInt32(PostgresType.OID);
            await(NullableHandler <TMember> .Exists
                ? NullableHandler <TMember> .WriteAsync(_handler, _get(ref composite), buffer, lengthCache, null, async, cancellationToken)
                : _handler.WriteWithLengthInternal(_get(ref composite), buffer, lengthCache, null, async, cancellationToken));
        }
Esempio n. 4
0
 public override void Write(NpgsqlTid value, NpgsqlWriteBuffer buf, NpgsqlParameter parameter)
 {
     buf.WriteUInt32(value.BlockNumber);
     buf.WriteUInt16(value.OffsetNumber);
 }
Esempio n. 5
0
 /// <inheritdoc />
 public override void Write(uint value, NpgsqlWriteBuffer buf, NpgsqlParameter?parameter)
 => buf.WriteUInt32(value);