Treat the TWKB empty flag as a zero count in the parser

Aperta
#729 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
72/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
data

Direzione di ricerca

Start by reading geom/twkb_parser.go, in particular nextGeometry and the parse*/next* pairs for each geometry type. Confirm the changes from #723 are present at the base commit before editing, then add parseCount and route the count reads in the next* functions through it, deleting the now-redundant parse* wrappers except parsePoint and the numGeoms == 0 guard in nextGeometryCollection. Run go test ./geom with the existing tests unchanged; done means the suite passes and callers see no behavioural change.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

cleanup

The TWKB parser has a parse* and a next* function for each geometry type. Each parse* function is called once, from nextGeometry, after the headers have been read. It returns an empty geometry when the "is empty" flag is set in the header, and otherwise calls next*, which parses the body.

The split is needed for Point, LineString and Polygon. nextPoint, nextLineString and nextPolygon also parse the members of the multi types, and those members don't have headers. For MultiPoint, MultiLineString, MultiPolygon and GeometryCollection, next* is only called from its parse*.

Suggested change

A geometry with the flag set doesn't have a body, which amounts to a count of zero. One helper can express that where the count is read:

// parseCount reads the count that starts the body of a geometry. A geometry
// flagged as empty doesn't have a body, so its count is zero.
func (p *twkbParser) parseCount() (uint64, error) {
	if p.isEmpty {
		return 0, nil
	}
	return p.parseUnsignedVarint()
}

With #723 merged, the next* functions return an empty geometry of the right coordinates type for a count of zero. If they read their counts through parseCount:

  • parseLineString, parsePolygon, parseMultiPoint, parseMultiLineString, parseMultiPolygon and parseGeometryCollection can be removed, and nextGeometry can call the next* functions directly.
  • parsePoint stays, because a Point doesn't have a count.
  • The numGeoms == 0 check in nextGeometryCollection stays, because the coordinates type of a collection without children has to come from its header.

The flag is never set while a member is being parsed, because a flagged geometry has a count of zero and its members aren't read. So nextPoint, nextLineString and nextPolygon parse members the same way as they do today.

I tried this on top of #723 at 056e055. It is 21 insertions and 54 deletions in geom/twkb_parser.go, and go test ./geom passes with the tests unchanged. Callers can't observe the change.

Relation to #725

#725 needs a check on the element count in four of the next* functions. parseCount would be one place to put that check.

Lingua principale
Go
Stelle
176
Fork
27
Merge medio
1g 20h
PR unite (30g)
6

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di peterstace/simplefeatures

Tutte le issue di peterstace/simplefeatures

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.