Skip to content

Commit

Permalink
Replace interface{} with any
Browse files Browse the repository at this point in the history
  • Loading branch information
maguro committed Oct 27, 2024
1 parent f3dc5c5 commit e01d8e1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/pbf/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func runInfo(in io.Reader, ncpu uint16, extended bool) *extendedHeader {

func renderJSON(info *extendedHeader, extended bool) {
// marshall the smallest struct needed
var v interface{}
var v any
if extended {
v = info
} else {
Expand Down
10 changes: 5 additions & 5 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ type encoded struct {
}

type decoded struct {
elements []interface{}
elements []any
err error
}

type pair struct {
element interface{}
element any
err error
}

Expand Down Expand Up @@ -184,7 +184,7 @@ func NewDecoder(ctx context.Context, reader io.Reader, opts ...DecoderOption) (*
// or Relation struct representing the underlying OpenStreetMap PBF data, or
// error encountered. The end of the input stream is reported by an io.EOF
// error.
func (d *Decoder) Decode() (interface{}, error) {
func (d *Decoder) Decode() (any, error) {
decoded, more := <-d.pairs
if !more {
return nil, io.EOF
Expand Down Expand Up @@ -321,7 +321,7 @@ func coalesce(cfg decoderOptions, outputs ...chan decoded) (pairs chan pair) {
// elements unmarshals an array of OSM elements from an array of protobuf encoded
// bytes. The bytes could possibly be compressed; zlibBuf is used to facilitate
// decompression.
func elements(header *protobuf.BlobHeader, blob *protobuf.Blob, zlibBuf *bytes.Buffer) ([]interface{}, error) {
func elements(header *protobuf.BlobHeader, blob *protobuf.Blob, zlibBuf *bytes.Buffer) ([]any, error) {
var buf []byte

switch {
Expand Down Expand Up @@ -368,7 +368,7 @@ func elements(header *protobuf.BlobHeader, blob *protobuf.Blob, zlibBuf *bytes.B
return nil, err
}

return []interface{}{h}, nil
return []any{h}, nil
}
case "OSMData":
return parsePrimitiveBlock(buf)
Expand Down
20 changes: 10 additions & 10 deletions decoder_elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (
"m4o.io/pbf/protobuf"
)

func parsePrimitiveBlock(buffer []byte) ([]interface{}, error) {
func parsePrimitiveBlock(buffer []byte) ([]any, error) {
pb := &protobuf.PrimitiveBlock{}
if err := proto.Unmarshal(buffer, pb); err != nil {
return nil, err
}

c := newBlockContext(pb)

elements := make([]interface{}, 0)
elements := make([]any, 0)
for _, pg := range pb.GetPrimitivegroup() {
elements = append(elements, c.decodeNodes(pg.GetNodes())...)
elements = append(elements, c.decodeDenseNodes(pg.GetDense())...)
Expand All @@ -40,8 +40,8 @@ func parsePrimitiveBlock(buffer []byte) ([]interface{}, error) {
return elements, nil
}

func (c *blockContext) decodeNodes(nodes []*protobuf.Node) (elements []interface{}) {
elements = make([]interface{}, len(nodes))
func (c *blockContext) decodeNodes(nodes []*protobuf.Node) (elements []any) {
elements = make([]any, len(nodes))

for i, node := range nodes {
elements[i] = &Node{
Expand All @@ -56,9 +56,9 @@ func (c *blockContext) decodeNodes(nodes []*protobuf.Node) (elements []interface
return elements
}

func (c *blockContext) decodeDenseNodes(nodes *protobuf.DenseNodes) []interface{} {
func (c *blockContext) decodeDenseNodes(nodes *protobuf.DenseNodes) []any {
ids := nodes.GetId()
elements := make([]interface{}, len(ids))
elements := make([]any, len(ids))

tic := c.newTagsContext(nodes.GetKeysVals())
dic := c.newDenseInfoContext(nodes.GetDenseinfo())
Expand All @@ -83,8 +83,8 @@ func (c *blockContext) decodeDenseNodes(nodes *protobuf.DenseNodes) []interface{
return elements
}

func (c *blockContext) decodeWays(nodes []*protobuf.Way) []interface{} {
elements := make([]interface{}, len(nodes))
func (c *blockContext) decodeWays(nodes []*protobuf.Way) []any {
elements := make([]any, len(nodes))

for i, node := range nodes {
refs := node.GetRefs()
Expand All @@ -108,8 +108,8 @@ func (c *blockContext) decodeWays(nodes []*protobuf.Way) []interface{} {
return elements
}

func (c *blockContext) decodeRelations(nodes []*protobuf.Relation) []interface{} {
elements := make([]interface{}, len(nodes))
func (c *blockContext) decodeRelations(nodes []*protobuf.Relation) []any {
elements := make([]any, len(nodes))

for i, node := range nodes {
elements[i] = &Relation{
Expand Down

0 comments on commit e01d8e1

Please sign in to comment.