TPsv INpgsqlSimpleTypeHandler <TPsv> .Read(NpgsqlReadBuffer buf, int len, [CanBeNull] FieldDescription fieldDescription) => ReadPsv(buf, len, fieldDescription);
ValueTask <LineString> INpgsqlTypeHandler <LineString> .Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription?fieldDescription) => ReadCore <LineString>(buf, len);
ValueTask <GeometryCollection> INpgsqlTypeHandler <GeometryCollection> .Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription?fieldDescription) => ReadCore <GeometryCollection>(buf, len);
/// <inheritdoc /> public override TAny Read <TAny>(NpgsqlReadBuffer buf, int len, FieldDescription?fieldDescription = null) => Read <TAny>(buf, len, false, fieldDescription).Result;
public override ValueTask <Geometry> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription?fieldDescription = null) => ReadCore <Geometry>(buf, len);
sbyte INpgsqlSimpleTypeHandler <sbyte> .Read(NpgsqlReadBuffer buf, int len, FieldDescription?fieldDescription) => checked ((sbyte)Read(buf, len, fieldDescription));
public override char Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null) => (char)buf.ReadByte();
async ValueTask <MultiLineString> INpgsqlTypeHandler <MultiLineString> .Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription?fieldDescription) => (MultiLineString) await ReadGeometry(buf, async);
async ValueTask <GeometryCollection> INpgsqlTypeHandler <GeometryCollection> .Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription?fieldDescription) => (GeometryCollection) await ReadGeometry(buf, async);
/// <inheritdoc /> public override TimeSpan Read(NpgsqlReadBuffer buf, int len, FieldDescription?fieldDescription = null) => (TimeSpan)((INpgsqlSimpleTypeHandler <NpgsqlTimeSpan>) this).Read(buf, len, fieldDescription);
public override ValueTask <GeoJSONObject> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription?fieldDescription = null) => ReadGeometry(buf, async);
public override ValueTask <string> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription?fieldDescription = null) => base.Read(buf, len, async, fieldDescription);
/// <summary> /// Reads a column as the type handler's provider-specific type. If it is not already entirely in /// memory, sync or async I/O will be performed as specified by <paramref name="async"/>. /// </summary> internal override async ValueTask <object> ReadPsvAsObject(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null) => await Read <TPsv>(buf, len, async, fieldDescription);
/// <summary> /// Reads a column as the type handler's provider-specific type, assuming that it is already entirely /// in memory (i.e. no I/O is necessary). Called by <see cref="NpgsqlDefaultDataReader"/>, which /// buffers entire rows in memory. /// </summary> internal override object ReadPsvAsObject(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null) => Read <TPsv>(buf, len, fieldDescription);
// Adjust from 1 microsecond to 100ns. Time zone (in seconds) is inverted. public override OffsetTime Read(NpgsqlReadBuffer buf, int len, FieldDescription?fieldDescription = null) => new(
async ValueTask <IGeometryObject> INpgsqlTypeHandler <IGeometryObject> .Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription?fieldDescription) => (IGeometryObject) await ReadGeometry(buf, async);
/// <inheritdoc /> public override short Read(NpgsqlReadBuffer buf, int len, FieldDescription?fieldDescription = null) => buf.ReadInt16();
async ValueTask <GeoJSONObject> ReadGeometryCore(NpgsqlReadBuffer buf, bool async, BoundingBoxBuilder?boundingBox) { await buf.Ensure(SizeOfHeader, async); var littleEndian = buf.ReadByte() > 0; var type = (EwkbGeometryType)buf.ReadUInt32(littleEndian); GeoJSONObject geometry; NamedCRS? crs = null; if (HasSrid(type)) { await buf.Ensure(4, async); crs = GetCrs(buf.ReadInt32(littleEndian)); } switch (type & EwkbGeometryType.BaseType) { case EwkbGeometryType.Point: { await buf.Ensure(SizeOfPoint(type), async); var position = ReadPosition(buf, type, littleEndian); boundingBox?.Accumulate(position); geometry = new Point(position); break; } case EwkbGeometryType.LineString: { await buf.Ensure(SizeOfLength, async); var coordinates = new Position[buf.ReadInt32(littleEndian)]; for (var i = 0; i < coordinates.Length; ++i) { await buf.Ensure(SizeOfPoint(type), async); var position = ReadPosition(buf, type, littleEndian); boundingBox?.Accumulate(position); coordinates[i] = position; } geometry = new LineString(coordinates); break; } case EwkbGeometryType.Polygon: { await buf.Ensure(SizeOfLength, async); var lines = new LineString[buf.ReadInt32(littleEndian)]; for (var i = 0; i < lines.Length; ++i) { var coordinates = new Position[buf.ReadInt32(littleEndian)]; for (var j = 0; j < coordinates.Length; ++j) { await buf.Ensure(SizeOfPoint(type), async); var position = ReadPosition(buf, type, littleEndian); boundingBox?.Accumulate(position); coordinates[j] = position; } lines[i] = new LineString(coordinates); } geometry = new Polygon(lines); break; } case EwkbGeometryType.MultiPoint: { await buf.Ensure(SizeOfLength, async); var points = new Point[buf.ReadInt32(littleEndian)]; for (var i = 0; i < points.Length; ++i) { await buf.Ensure(SizeOfHeader + SizeOfPoint(type), async); await buf.Skip(SizeOfHeader, async); var position = ReadPosition(buf, type, littleEndian); boundingBox?.Accumulate(position); points[i] = new Point(position); } geometry = new MultiPoint(points); break; } case EwkbGeometryType.MultiLineString: { await buf.Ensure(SizeOfLength, async); var lines = new LineString[buf.ReadInt32(littleEndian)]; for (var i = 0; i < lines.Length; ++i) { await buf.Ensure(SizeOfHeaderWithLength, async); await buf.Skip(SizeOfHeader, async); var coordinates = new Position[buf.ReadInt32(littleEndian)]; for (var j = 0; j < coordinates.Length; ++j) { await buf.Ensure(SizeOfPoint(type), async); var position = ReadPosition(buf, type, littleEndian); boundingBox?.Accumulate(position); coordinates[j] = position; } lines[i] = new LineString(coordinates); } geometry = new MultiLineString(lines); break; } case EwkbGeometryType.MultiPolygon: { await buf.Ensure(SizeOfLength, async); var polygons = new Polygon[buf.ReadInt32(littleEndian)]; for (var i = 0; i < polygons.Length; ++i) { await buf.Ensure(SizeOfHeaderWithLength, async); await buf.Skip(SizeOfHeader, async); var lines = new LineString[buf.ReadInt32(littleEndian)]; for (var j = 0; j < lines.Length; ++j) { var coordinates = new Position[buf.ReadInt32(littleEndian)]; for (var k = 0; k < coordinates.Length; ++k) { await buf.Ensure(SizeOfPoint(type), async); var position = ReadPosition(buf, type, littleEndian); boundingBox?.Accumulate(position); coordinates[k] = position; } lines[j] = new LineString(coordinates); } polygons[i] = new Polygon(lines); } geometry = new MultiPolygon(polygons); break; } case EwkbGeometryType.GeometryCollection: { await buf.Ensure(SizeOfLength, async); var elements = new IGeometryObject[buf.ReadInt32(littleEndian)]; for (var i = 0; i < elements.Length; ++i) { elements[i] = (IGeometryObject) await ReadGeometryCore(buf, async, boundingBox); } geometry = new GeometryCollection(elements); break; } default: throw UnknownPostGisType(); } geometry.CRS = crs; return(geometry); }
decimal INpgsqlSimpleTypeHandler <decimal> .Read(NpgsqlReadBuffer buf, int len, FieldDescription?fieldDescription) => Read(buf, len, fieldDescription);
internal CommandCompleteMessage Load(NpgsqlReadBuffer buf, int len) { Rows = 0; OID = 0; var bytes = buf.Buffer; var i = buf.ReadPosition; buf.Skip(len); switch (bytes[i]) { case (byte)'I': if (!AreEqual(bytes, i, "INSERT ")) { goto default; } StatementType = StatementType.Insert; i += 7; OID = (uint)ParseNumber(bytes, ref i); i++; Rows = ParseNumber(bytes, ref i); return(this); case (byte)'D': if (!AreEqual(bytes, i, "DELETE ")) { goto default; } StatementType = StatementType.Delete; i += 7; Rows = ParseNumber(bytes, ref i); return(this); case (byte)'U': if (!AreEqual(bytes, i, "UPDATE ")) { goto default; } StatementType = StatementType.Update; i += 7; Rows = ParseNumber(bytes, ref i); return(this); case (byte)'S': if (!AreEqual(bytes, i, "SELECT ")) { goto default; } StatementType = StatementType.Select; i += 7; Rows = ParseNumber(bytes, ref i); return(this); case (byte)'M': if (!AreEqual(bytes, i, "MOVE ")) { goto default; } StatementType = StatementType.Move; i += 5; Rows = ParseNumber(bytes, ref i); return(this); case (byte)'F': if (!AreEqual(bytes, i, "FETCH ")) { goto default; } StatementType = StatementType.Fetch; i += 6; Rows = ParseNumber(bytes, ref i); return(this); case (byte)'C': if (!AreEqual(bytes, i, "COPY ")) { goto default; } StatementType = StatementType.Copy; i += 5; Rows = ParseNumber(bytes, ref i); return(this); default: StatementType = StatementType.Other; return(this); } }
long INpgsqlSimpleTypeHandler <long> .Read(NpgsqlReadBuffer buf, int len, [CanBeNull] FieldDescription fieldDescription) => buf.ReadByte();
/// <inheritdoc /> protected override NpgsqlDateTime ReadPsv(NpgsqlReadBuffer buf, int len, FieldDescription?fieldDescription = null) => ReadTimeStamp(buf, len, fieldDescription);
/// <inheritdoc /> public override ValueTask <NpgsqlRange <TElement> > Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription?fieldDescription = null, CancellationToken cancellationToken = default) => DoRead <TElement>(buf, len, async, fieldDescription, cancellationToken);
// PostgreSQL time resolution == 1 microsecond == 10 ticks /// <inheritdoc /> public override TimeSpan Read(NpgsqlReadBuffer buf, int len, FieldDescription?fieldDescription = null) => new(buf.ReadInt64() * 10);
ValueTask <Point> INpgsqlTypeHandler <Point> .Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription?fieldDescription) => ReadCore <Point>(buf, len);
// PostgreSQL time resolution == 1 microsecond == 10 ticks public override LocalTime Read(NpgsqlReadBuffer buf, int len, FieldDescription?fieldDescription = null) => LocalTime.FromTicksSinceMidnight(buf.ReadInt64() * 10);
ValueTask <MultiPolygon> INpgsqlTypeHandler <MultiPolygon> .Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription?fieldDescription) => ReadCore <MultiPolygon>(buf, len);
TimeOnly INpgsqlSimpleTypeHandler <TimeOnly> .Read(NpgsqlReadBuffer buf, int len, FieldDescription?fieldDescription) => _bclHandler.Read <TimeOnly>(buf, len, fieldDescription);
ValueTask <T> ReadCore <T>(NpgsqlReadBuffer buf, int len) where T : Geometry => new ValueTask <T>((T)_reader.Read(buf.GetStream(len, false)));
/// <summary> /// Reads a value of type <typeparamref name="TPsv"/> with the given length from the provided buffer, /// with the assumption that it is entirely present in the provided memory buffer and no I/O will be /// required. /// </summary> /// <param name="buf">The buffer from which to read.</param> /// <param name="len">The byte length of the value. The buffer might not contain the full length, requiring I/O to be performed.</param> /// <param name="fieldDescription">Additional PostgreSQL information about the type, such as the length in varchar(30).</param> /// <returns>The fully-read value.</returns> protected abstract TPsv ReadPsv(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null);