[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pack/Unpack Functions


On 2/24/25 7:52 AM, Benoît Minisini wrote:
Le 24/02/2025 à 11:23, Justin Percy a écrit :
Hi,

I am trying to port over some PHP code to Gambas and really need Pack/ Unpack functions https://www.php.net/manual/en/ function.pack.php

Any help would be appreciated, thanks!

Justin



These functions are PHP-specific. You must implement them "by hand" in Gambas, using OPEN STRING, WRITE and READ.

Regards,


Justin, if you don't need compatibility with PHP-packed binary strings, keep in mind that you can serialize an object such as, for example, a collection.

[code]
' Gambas module file

Public Sub Main()

  Dim cData1, cData2 As Collection
  Dim hStringStream As Stream
  Dim sData As String

  cData1 = ["one": 1, "two": 2, "three": 3]

  hStringStream = Open String For Write
  Write #hStringStream, cData1 As Collection
  sData = Close hStringStream

  hStringStream = Open String sData For Read
  cData2 = Read #hStringStream As Collection
  Close hStringStream

  For Each sValue As String In cData2
    Print cData2.Key, sValue
  Next

End
[/code]


--
Lee

--- Gambas User List Netiquette [https://gambaswiki.org/wiki/doc/netiquette] ----
--- Gambas User List Archive [https://lists.gambas-basic.org/archive/user] ----


References:
Pack/Unpack FunctionsJustin Percy <justin@xxxxxxxxxxxxxxx>
Re: Pack/Unpack FunctionsBenoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>