Skip to content

Commit

Permalink
feat: define unknown template for iterating messages without raising …
Browse files Browse the repository at this point in the history
…errors
  • Loading branch information
scorix committed Jan 6, 2025
1 parent 45d3d0c commit 21df3c3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
27 changes: 27 additions & 0 deletions pkg/grib2/drt/grid_point/unknown.go
Original file line number Diff line number Diff line change
@@ -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")
}
9 changes: 5 additions & 4 deletions pkg/grib2/drt/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

0 comments on commit 21df3c3

Please sign in to comment.