delphi-blocks / WiRL

WiRL: RESTful Library for Delphi
https://wirl.delphiblocks.dev/
Apache License 2.0
238 stars 84 forks source link

Can't write a MessageBodyReader for the TBytes (or any other dynamic array) type #57

Open fperana opened 3 months ago

fperana commented 3 months ago

I need to write a custom MessageBodyReader (and MessageBodyWriter, this already works) to handle the TBytes type, such that this particular dynamic array type would be treated as a byte stream. This gives the ability to pass/return TBytes to/from a resource declared as consuming/producing a TMediaType.APPLICATION_OCTET_STREAM, without the need to create and having to deal with TMemoryStream (which seems to be the only currently/natively supported type when consuming/producing TMediaType.APPLICATION_OCTET_STREAM).

In reference to the following TODO:

https://github.com/delphi-blocks/WiRL/blob/e72dad1eff26ebe81d1e2acfc1ff63ffea8cb608/Source/Core/WiRL.Core.Application.Worker.pas#L396

The current code actually inhibits the ability to write such a custom MessageBodyReader for the TBytes type, which is a dynamic array and these are treated by special code that doesn't use the MessageBodyReader registry. Solving this TODO would probably solve my issue (well, I tried and it actually solves it, but I can't foresee the drawbacks).