Fetch binary chunk and draw on canvas

This commit is contained in:
Guntis Smaukstelis
2025-02-03 23:33:28 +02:00
parent c1b1226678
commit df8d16ed4a
18 changed files with 898 additions and 6 deletions
+10
View File
@@ -45,6 +45,8 @@ object GribParser {
(conversion, bitsPerDataPoint, len5) = res5
ptr6 = ptr5 + len5
len6 <- parse6(path, ptr6)
ptr7 = ptr6 + len6
len7 <- parse7(path, ptr7)
sections = List(
GribSection(0, ptr, len0),
GribSection(1, ptr1, len1),
@@ -52,6 +54,7 @@ object GribParser {
GribSection(4, ptr4, len4),
GribSection(5, ptr5, len5),
GribSection(6, ptr6, len6),
GribSection(7, ptr7, len7),
)
title = Codes.codesToString(meteo.discipline, meteo.category, meteo.product)
grib = Grib(version, gribLength, title, grid, meteo, time, conversion, bitsPerDataPoint, sections)
@@ -147,6 +150,13 @@ object GribParser {
} yield length
}
private def parse7(path: Path, ptr: Long): IO[Int] = {
for {
bytes <- readBytes(path, ptr, 64)
length = ByteBuffer.wrap(bytes.slice(0, 4)).getInt
} yield length
}
private def readBytes(path: Path, ptr: Long, len: Int): IO[Array[Byte]] = {
Files[IO].readRange(path, 1024, ptr, ptr + len)
.compile
+4 -1
View File
@@ -7,7 +7,7 @@ import data.DataService
import db.PostgresService
import fetch.FetchService
import parse.Aggregate
import server.ValidateRoutes.{AggFieldList, AggKey, CityList, DateTimeRange, Granularity, ValidateDate, ValidateDateTime, ValidateMonths, ValidateZonedDateTime}
import server.ValidateRoutes.{AggFieldList, AggKey, CityList, DateTimeRange, Granularity, ValidateDate, ValidateDateTime, ValidateMonths, ValidateInt, ValidateZonedDateTime}
import io.circe.{Json, Printer}
import org.http4s._
import org.http4s.dsl.io._
@@ -62,6 +62,9 @@ class Server(postgresService: PostgresService, fetch: FetchService, log: Logger[
case GET -> Root / "show" / "grib-list" =>
DataService.getFileList().flatMap(fileList => Ok(fileList.asJson))
// TODO implement binary-chunk/ get request
case GET -> Root / "grib" / "binary-chunk" / ValidateInt(binaryOffset) / ValidateInt(binaryLength) / fileName =>
DataService.getBinaryChunk(binaryOffset, binaryLength, fileName).flatMap(buffer => Ok(buffer))
@@ -89,4 +89,10 @@ object ValidateRoutes {
}
}
}
object ValidateInt {
def unapply(str: String): Option[Int] = {
Option(str.toInt)
}
}
}