Repository navigation
Read and write the WKB of every exported class - #30
Merged
estebanzimanyi merged 2 commits intoOct 31, 2026
Merged
Conversation
size_t, ssize_t and uintptr_t are pointer-sized, so 64-bit in the wasm64 module, and ccall passes a 64-bit argument as a BigInt: a size_t sent as a number makes ccall throw "Cannot convert 20 to a BigInt". The generator types them as the 64-bit integers it already passes and returns as BigInt, so the 29 wrappers that take or return one, the 17 *_from_wkb readers among them, reach MEOS. The wrappers are regenerated from the catalog of MobilityDB master 7de78631f5: 4053 wrappers, none skipped and none duplicated.
Every exported temporal class reads its hex WKB through fromHexWKB and its WKB bytes through fromBinary, and writes them through asHexWKB and asBinary; the sets, spans, span sets and boxes, which read hex WKB, read and write WKB bytes too. asBinary returns a Uint8Array copied out of the WASM heap, with the MEOS buffer freed, and fromBinary takes a Uint8Array whose length is its own (core/functions/wkb.ts). The module exports HEAPU8 for it. asBinary and asHexWKB write plain WKB, as asBinary and asHexWKB do in MobilityDB: the variant defaults to 0, the one an empty endian argument gives, and 0x08 or 0x10 chooses the byte order. temporal_as_hexwkb_w takes the variant. TGeomPoint, TGeogPoint and STBox write their SRID through asEWKB and asHexEWKB and read it back through fromEWKB and fromHexEWKB. A temporal reader checks the base type of the value it reads, so TBool.fromHexWKB of a temporal integer throws a TypeError rather than wrapping it. The box writers free the size slot they allocate. Each class has a test that fromBinary(asBinary(v)) equals v and that the bytes are the WKB asHexWKB writes in hex. Each temporal class also tests fromHexWKB(asHexWKB(v)), both byte orders and the refusal of another temporal type; TGeomPoint, TGeogPoint and STBox test that a value with SRID 4326 round-trips without it through asHexWKB and with it through asHexEWKB and asEWKB. The guide shows the readers and writers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every exported temporal class reads its hex WKB through fromHexWKB and its
WKB bytes through fromBinary, and writes them through asHexWKB and
asBinary; the sets, spans, span sets and boxes, which read hex WKB, read
and write WKB bytes too. asBinary returns a Uint8Array copied out of the
WASM heap, with the MEOS buffer freed, and fromBinary takes a Uint8Array
whose length is its own (core/functions/wkb.ts). The module exports
HEAPU8 for it.
asBinary and asHexWKB write plain WKB, as asBinary and asHexWKB do in
MobilityDB: the variant defaults to 0, the one an empty endian argument
gives, and 0x08 or 0x10 chooses the byte order. temporal_as_hexwkb_w takes
the variant. TGeomPoint, TGeogPoint and STBox write their SRID through
asEWKB and asHexEWKB and read it back through fromEWKB and fromHexEWKB.
A temporal reader checks the base type of the value it reads, so
TBool.fromHexWKB of a temporal integer throws a TypeError rather than
wrapping it. The box writers free the size slot they allocate.
Each class has a test that fromBinary(asBinary(v)) equals v and that the
bytes are the WKB asHexWKB writes in hex. Each temporal class also tests
fromHexWKB(asHexWKB(v)), both byte orders and the refusal of another
temporal type; TGeomPoint, TGeogPoint and STBox test that a value with
SRID 4326 round-trips without it through asHexWKB and with it through
asHexEWKB and asEWKB. The guide shows the readers and writers.