diff --git a/pkg/grib2/drt/grid_point/unknown.go b/pkg/grib2/drt/grid_point/unknown.go new file mode 100644 index 0000000..bd10244 --- /dev/null +++ b/pkg/grib2/drt/grid_point/unknown.go @@ -0,0 +1,27 @@ +package gridpoint + +import ( + "fmt" + + "github.com/scorix/grib-go/internal/pkg/bitio" +) + +type Unknown struct { + numVals int +} + +func NewUnknown(numVals int) *Unknown { + return &Unknown{numVals: numVals} +} + +func (u *Unknown) GetNumVals() int { + return u.numVals +} + +func (u *Unknown) Definition() any { + return nil +} + +func (u *Unknown) ReadAllData(r *bitio.Reader) ([]float32, error) { + return nil, fmt.Errorf("unknown data template") +} diff --git a/pkg/grib2/drt/template.go b/pkg/grib2/drt/template.go index d12a487..2856984 100644 --- a/pkg/grib2/drt/template.go +++ b/pkg/grib2/drt/template.go @@ -3,7 +3,6 @@ package drt import ( "encoding/binary" "encoding/json" - "fmt" "github.com/scorix/grib-go/internal/pkg/bitio" "github.com/scorix/grib-go/pkg/grib2/drt/datapacking" @@ -82,7 +81,7 @@ func ReadTemplate(r datapacking.BitReader, n TemplateNumber, numVals int) (Templ return gridpoint.NewPortableNetworkGraphics(tplDef, numVals), nil } - return nil, fmt.Errorf("data template not implemented: %d", n) + return gridpoint.NewUnknown(numVals), nil } // TemplateMarshaler @@ -168,7 +167,9 @@ func (tm *TemplateMarshaler) UnmarshalJSON(data []byte) error { tm.Template = gridpoint.NewPortableNetworkGraphics(tplDef, t.Vals) return nil - } - return fmt.Errorf("data template not implemented: %d", t.Number) + default: + tm.Template = gridpoint.NewUnknown(t.Vals) + return nil + } }