Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Response msgpack content

Post Reply
dilfich
Posts: 368
Joined: Thu Nov 30, 2017 1:17 am

Response msgpack content

Post by dilfich »

Can someone tell me how to decode the data if it is in the form of an msgpack? :?
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Response msgpack content

Post by salvadordf »

I've never used that format but perhaps these projects can help you :
https://github.com/arthurprs/msgpack-delphi
https://github.com/ymofen/msgpack-delphi
dilfich
Posts: 368
Joined: Thu Nov 30, 2017 1:17 am

Re: Response msgpack content

Post by dilfich »

Yes, I've seen it, as well as the online converter. https://msgpack.solder.party/
Example of ResponseFilterBrowser
How do I get this data in binary form? It's not clear what's in FStream. :(

In a regular browser, it looks like this - https://postimg.cc/wR6wsp30
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Response msgpack content

Post by salvadordf »

The ResponseFilterBrowser can be modified to copy the raw binary contents of any resource to FStream.

See these functions and read all the code comments in the demo and the interface methods used by the demo :
  • TResponseFilterBrowserFrm.IsMyResource
  • TResponseFilterBrowserFrm.CopyScript
dilfich
Posts: 368
Joined: Thu Nov 30, 2017 1:17 am

Re: Response msgpack content

Post by dilfich »

Everything is clear with this, but how to read data from an FStream correctly?

I found examples on the internet, but it doesn't work(
The online converter does not accept this result.

Code: Select all

function BitStreamToHexStr(AStream: TMemoryStream): string;
const
 HexArr: array[0..15] of char = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
var
 AByte: Byte;
 i: Integer;
begin
 SetLength(Result, AStream.Size * 2);
 for i := 0 to AStream.Size - 1 do
 begin
   AByte := PByteArray(AStream.Memory)[i];
   Result[i * 2 + 1] := HexArr[AByte shr 4];
   Result[i * 2 + 2] := HexArr[AByte and $0F];
 end;
end;
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Response msgpack content

Post by salvadordf »

There are many ways to do that and you'll probably find simpler code that this but try this example to convert a stream to TBytes :
https://docwiki.embarcadero.com/CodeExamples/Sydney/en/TStreamReadBuffer_(Delphi)

If the framework you use doesn't support TBytes as input then convert each byte to hex with IntToHex
Post Reply