Skip to content

Read and write the WKB of every exported class - #30

Merged
estebanzimanyi merged 2 commits into
MobilityDB:mainfrom
estebanzimanyi:feat/io-readers-writers
Oct 31, 2026
Merged

estebanzimanyi merged 2 commits into
MobilityDB:mainfrom
estebanzimanyi:feat/io-readers-writers

Conversation

@estebanzimanyi

Copy link
Copy Markdown
Member

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.

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.
@estebanzimanyi
estebanzimanyi merged commit a6a5284 into MobilityDB:main Oct 31, 2026
3 checks passed
@estebanzimanyi
estebanzimanyi deleted the feat/io-readers-writers branch October 31, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant