Treat the TWKB empty flag as a zero count in the parser
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 72/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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,parseMultiPolygonandparseGeometryCollectioncan be removed, andnextGeometrycan call thenext*functions directly.parsePointstays, because a Point doesn't have a count.- The
numGeoms == 0check innextGeometryCollectionstays, 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.
- Dominant language
- Go
- Stars
- 176
- Forks
- 27
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 6
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from peterstace/simplefeatures
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
peterstace/simplefeatures#726 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
peterstace/simplefeatures#725 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 58/100
peterstace/simplefeatures#724 ·
-
cleanup
Difficulty 3/5 1-2 days Newbie friendliness 35/100
peterstace/simplefeatures#722 ·
-
bug
Difficulty 3/5 Half a day Newbie friendliness 45/100
peterstace/simplefeatures#721 ·
All issues in peterstace/simplefeatures
Similar issues
-
bug raised-by:reviewer
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
medici-finance/assay#7655 ·
Maintainers usually reply within 1 day
-
helm chart: make DaemonSet pod affinity configurable via values.yamlPossibly taken @Young-Zen claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
flannel-io/flannel#2632 ·
Maintainers usually reply within 6 days
-
go-vulnerability security-scan
Difficulty 1/5 Under an hour Newbie friendliness 72/100
teslashibe/agent-go#36 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nwverse/persona#15194 · 1 comment ·
Maintainers usually reply within 1 day
-
bug flaky-test
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rosskukulinski/tailworks#411 ·
Maintainers usually reply within 1 day