A few holes (imho) in the ecosystem of libraries
Andrew
andrewlalisofficial at gmail.com
Mon May 15 14:04:39 UTC 2023
On Monday, 15 May 2023 at 13:53:15 UTC, Guillaume Piolat wrote:
> Can't use exceptions since downstream user will use that on
> WebASM, -betterC not having class etc.
> And I cannot use your library for similar reasons, it uses the
> runtime, it uses exceptions, it has generic names etc. We have
> a lot of such libraries, but we have to keep in mind people use
> D because they are performance-oriented and they may have
> druntime constraints. Ideally the D runtime would be
> pay-as-you-go and infinitely portable, but that's not the
> current state of things.
Yeah, please bear in mind that my goal is to make my library
ultimately compatible with those not using the D runtime, but for
prototyping I have indeed made use of exceptions and `std.traits`
just to get something working. But the idea is to be able to
achieve your desired functionality like this:
```d
bool getImageInfo(S)(S* stream) if (isByteInputStream!S)
{
ubyte[3] buf;
int bytes = stream.read(buf[]);
if (bytes != 3) return false;
_dataOffset = buf[0];
_cmapType = buf[1];
_imageType = buf[2];
return true;
}
```
Or I am also working on a concept of "data streams" which
automatically convert between byte arrays and scalar types in an
endian-aware manner:
```d
void getImageInfo(S)(S* stream) if (isByteInputStream!S)
{
auto dIn = dataInputStreamFor(stream, Endianness.BigEndian);
_dataOffset = dIn.read!ubyte();
_cmapType = dIn.read!ubyte();
_imageType = dIn.read!ubyte();
}
```
But I've only been working on it for a few days, I think that
your input would be greatly appreciated; if you could list on
that thread some more examples of what you need from a binary IO
library.
More information about the Digitalmars-d
mailing list