internal override DataRowMessage Load(ReadBuffer buf)
 {
     buf.Ensure(sizeof(short));
     NumColumns = buf.ReadInt16();
     Buffer = buf;
     Column = -1;
     ColumnLen = -1;
     PosInColumn = 0;
     return this;
 }
Example #2
0
        internal override T2 ReadFully <T2>(ReadBuffer buf, int len, FieldDescription fieldDescription = null)
        {
            buf.Ensure(len);
            var asTypedHandler = this as ISimpleTypeHandler <T2>;

            if (asTypedHandler == null)
            {
                throw new InvalidCastException(fieldDescription == null
                    ? "Can't cast database type to " + typeof(T2).Name
                    : $"Can't cast database type {fieldDescription.Handler.PgDisplayName} to {typeof(T2).Name}"
                                               );
            }

            return(asTypedHandler.Read(buf, len, fieldDescription));
        }
Example #3
0
        /// <remarks>
        /// A type handler may implement ISimpleTypeHandler for types other than its primary one.
        /// This is why this method has type parameter T2 and not T.
        /// </remarks>
        internal override async ValueTask <T2> Read <T2>(ReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
        {
            await buf.Ensure(len, async);

            var asTypedHandler = this as ISimpleTypeHandler <T2>;

            if (asTypedHandler == null)
            {
                buf.Skip(len);  // Perform this in sync for performance
                throw new SafeReadException(new InvalidCastException(fieldDescription == null
                    ? "Can't cast database type to " + typeof(T2).Name
                    : $"Can't cast database type {fieldDescription.Handler.PgDisplayName} to {typeof(T2).Name}"
                                                                     ));
            }

            return(asTypedHandler.Read(buf, len, fieldDescription));
        }
Example #4
0
        internal ReadBuffer EnsureOrAllocateTemp(int count)
        {
            if (count <= Size)
            {
                Ensure(count);
                return(this);
            }

            // Worst case: our buffer isn't big enough. For now, allocate a new buffer
            // and copy into it
            // TODO: Optimize with a pool later?
            var tempBuf = new ReadBuffer(Connector, Underlying, count, TextEncoding);

            CopyTo(tempBuf);
            Clear();
            tempBuf.Ensure(count);
            return(tempBuf);
        }
Example #5
0
        internal ReadBuffer EnsureOrAllocateTemp(int count)
        {
            if (count <= Size) {
                Ensure(count);
                return this;
            }

            // Worst case: our buffer isn't big enough. For now, allocate a new buffer
            // and copy into it
            // TODO: Optimize with a pool later?
            var tempBuf = new ReadBuffer(Connector, Underlying, count, TextEncoding);
            CopyTo(tempBuf);
            Clear();
            tempBuf.Ensure(count);
            return tempBuf;
        }