#1 2020-09-12 10:43:18

radexpol
Member
From: Poland, Krk
Registered: 2019-11-29
Posts: 116

TRawByteStringDynArray and response in base64

type
  TAgentItem = class(TCollectionItem)
     property Queues: TRawByteStringDynArray read FQueues write FQueues;
  end;

  IAgents = interface(IInvokable)
    ['{69D97B11-3143-471F-B380-F706A3B6F6CB}']
    procedure GetLogged(out agentCollection: TAgentsCollection);
    procedure Logout(const AgentID: integer);
  end;


implementation

var
  agent: TAgent;
  qList: TRawByteStringDynArray;
begin
  SetLength(qList, agent.QueueCount);
  for var j := 0 to agent.QueueCount - 1 do
    qList[j] := StringToUTF8(agent.Queue[j].Name);
  Queues := qList;
end;

the response for that query looks like that:

{"agentCollection":[{"ID":2,"Ident":"super01","Name":"super01 super01","Status":2,"UserStatusID":0,"PhoneRegistered":false,"IPAddress":"","Queues":["￰VGVzdA==","￰VFNfVGVtYXQx"]}]}

the Queue seems to be base64 encoded. What I'm doing wrong?

Offline

#2 2020-09-12 12:03:39

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,673
Website

Re: TRawByteStringDynArray and response in base64

This is as expected and documented.
https://synopse.info/files/html/Synopse … l#TITL_154
RawByteString are serialized as Base-64 encoded blobs.  They are meant to store any kind of content, maybe some binary including zeros. It is unsafe to store zeros in JSON, so we use Base-64 encoding for RawByteString.

If you want strings, use TRawUTF8DynArray. But they should not contain any #0 byte/character.

Offline

Board footer

Powered by FluxBB