The reason you needed the +2 on the %addr() of a varying length character variable, is that %addr() points at the first byte of the memory space the variable occupies. The first two bytes of that space is the length of the value. Depending on the max length of the variable, it could be 4 bytes, so using %ADDR(varying-length variable : *DATA) is better if you have a version of the compiler that supports it.
Since you are using %addr(binaryImage) + 2 for what I am assuming is the output variable, you probably are not setting the length of that variable length field, so the program thinks it is 0 even if you put something there. Variable length strings operate quickly because the computer ignores anything out past the length (stored in the first 2 or 4 bytes of the variable's memory space). You can put stuff there by using a pointer to address it, but if the length portion is 0, the variable is empty.
Mark Murphy
STAR BASE Consulting, Inc.
mmurphy@xxxxxxxxxxxxxxx
-----Michael Schutte <mschutte369@xxxxxxxxx> wrote: -----
To: "RPG programming on the IBM i / System i" <RPG400-L@xxxxxxxxxxxx>
From: Michael Schutte <mschutte369@xxxxxxxxx>
Date: 01/08/2016 11:37AM
Subject: BASE64 Encoded Character String to IFS.
I'm back to this project. A few years ago, I requested information. The
information provided was great at the time, however we were able to get the
USPS to send back the tracking number and just barcode it on our own
label. So taking an image and printing it on the printer was no longer
needed.
Now the account wants to change to UPS. UPS requires us to print their
label. I have to believe that someone has this working.
So here's what I have so far. FYI, the type of image is GIF. I know this
for certain this time. The XML document told me so. :-)
Originally...
D LABELIMAGE S 65535 VARYING
D binaryImage S 65535 VARYING
After getting the encoded Base64 string from an XML document. I ran this
code.
base64_decode(%addr(LabelImage)
:%Len(LabelImage)
:%addr(binaryImage)
:%size(binaryImage));
But this was failing saying that it couldn't decode x'9F'. I remembered
back to my days using WrtNoSection in CGIDEV2 that we had to add 2 to the
%Addr. I never understood why but I changed the code like so.
This time base64_decode didn't crash however, it appears that binary image
was empty in debug.
I was thinking that maybe it appeared that way because it was binary. Not
really sure how its supposed to look as this is really my first time using
this.
So I continued and tried to write the binaryimage to an IFS file. This
again could be wrong, I'm just not sure what exactly I need to do.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact
[javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.