olliv / data-record Goto Github PK
View Code? Open in Web Editor NEWExperimenting with a record type in Node.js [MOVED SEE URL]
Home Page: https://github.com/atelier-saulx/based/tree/main/packages/data-record
License: ISC License
Experimenting with a record type in Node.js [MOVED SEE URL]
Home Page: https://github.com/atelier-saulx/based/tree/main/packages/data-record
License: ISC License
Support all the field types.
Possible cases:
Should it be configurable?
The deserializer can't properly parse most of the array types.
A type like int32_be[123]
should define an array.
Currently it's fairly easy to read a struct with a pointer to union data. There are indeed multiple ways, either the struct might be declared with a union of pointers or the values can be casted or memcpy()
d depending on the case.
However, to create such a union in the JS side is a bit harder. Currently it requires one type definition per type in the union. If the header generator is used this will result a number of structs. data-record
will make sure the alignment is always correct so they C side can technically still just use one struct.
The biggest problem in implementing a union type is that the serializer would need extra info about which type to select. Using the write functions would work for non-pointers.
Currently serializing an array requires some string parsing that's know to be slow in V8. That part should be offloaded to the compiler.
Lines 11 to 14 in 16af00f
It would be more efficient to unroll the serialization loop for small structs and generate JS code for serializing.
Copy data after the end of the struct and make a pointer to it in the struct.
This doesn't need to support growing the buffer at serialization time, it's enough if the alloc function can create a large enough buffer.
Currently there are no checks in JS nor C.
Currently even when align
is set the nested records are not aligned properly.
Implement C enum type.
Default values both ways.
The following functions don't currently handle arrays correctly:
readValue(compiledDef, buf, path)
readString(compiledDef, buf, path, encoding)
writeValue(compiledDef, buf, path, value)
writeString(compiledDef, buf, path, value, encoding)
createReader(compiledDef, buf, path)
createStringReader(compiledDef, buf, path)
createWriter(compiledDef, buf, path)
They should either support arrays directly or there should be array variants. Latter sounds better as it could possibly also support indexing too.
Generate C headers and inline functions for accessing the data.
Currently compile
builds a sort of packed struct but it would be better to support normal structs for performance and ease of use.
Allow selecting between BE
, LE
, HOST
, NET
.
NET
should always add hton()
calls to the C header generator.
Add endianless-types that use either the selected endianness or the host endianness.
Line control could be possibly used to help with the error messages:
https://gcc.gnu.org/onlinedocs/cpp/Line-Control.html#Line-Control
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.