PowerBuilder’s Web Service prowess has increased significantly in recent releases from Appeon - in particular, PB2017 R2 and R3 release. These PowerBuilder releases have given us a new HTTP Client and RESTful Client capabilities that can utilize the newer JSON (JavaScript Object Notation) data format and the ever-popular XML (Extensible Markup Language) data format as well. When processing standard data type information in either the JSON or XML format, the ease of data exchange is very high. However, when trying to transfer binary data, the JSON and XML formats and the supporting HTTP transport layer for RESTful web services will not readily handle binary data.
To address this binary dilemma in the JSON and XML realm, today’s applications utilize the Base64 binary-to-text encoding mechanism to convert binary data into ASCII text sequences of the data. This allows the converted data to be injected into the JSON or XML schema and transmitted without upsetting the HTTP transport protocol. While it does increase the overall transmission data length when utilizing this encoding scheme, it is necessary in order to achieve the end goal of data exchange with these technologies.
In PB2017 R3, PowerBuilder will be updated to include new functions to both encode and decode binary data to and from the Base64 encoding scheme. The new PB built-in Base64Encode and Base64Decode commands can now perform the encoding in and out of the Base64 scheme using the standard PowerBuilder run-time engine support. For example, the PB Base64 PNG image used in this article would look like the following in a hexadecimal editor:
Figure 1- PowerBuilder Base64 Image in Hex
Using the new built-in Base64Encode method, the PNG image binary data is converted into a set of ASCII character sequences which can now be easily transmitted or even read by a simple text editor, as follows:
Figure 2- PowerBuilder Base64 PNG image in Base64 format
To support the Base64 functionality, Appeon has added a new “CoderObject” class to PB’s System Class area. The CoderObject also has some other interesting methods as well that support Hex and URL encoding and decoding as well, as follows:
Figure 3- New CoderObject system class
These new encoding and decoding techniques are another set of key enhancements to the PowerBuilder developer’s toolbox and must have in today’s ever-increasing data interchange world.