I would like to convert .NET System.Byte[] TO ABL MEMPTR (BLOB).
What is the most efficient way to achieve this?
I have already create code to get this done, but it performs much to slow. (see code snippet: METHODE 1)
I was try to increase the performance for the conversion by using base64 as an intermediate form.
But i can not get it to work. See code snippets METHODE 2 and METHODE 3)
/* METHOD 1 */
METHOD PUBLIC STATIC MEMPTR ConvertToMemptr( byteArray AS "System.Byte[]" ):
DEFINE VARIABLE aMEMPTR AS MEMPTR NO-UNDO.
DEFINE VARIABLE counter AS INTEGER NO-UNDO.
DEFINE VARIABLE memStream AS System.IO.MemoryStream NO-UNDO.
memStream = NEW System.IO.MemoryStream(byteArray).
SET-SIZE(aMEMPTR) = memStream:Length.
DO counter = 1 TO memStream:Length:
put-byte(aMEMPTR,counter)= memStream:ReadByte().
END.
RETURN aMEMPTR.
FINALLY:
memStream:Dispose().
DELETE OBJECT memStream.
END FINALLY.
END METHOD.
--------------------------------------------------------------------------------------
/* METHODE 2 Does not work -> Error converting Base64 to RAW (12119)
The argument to BASE64-DECODE does not contain a valid base64 string */
METHOD PUBLIC STATIC MEMPTR ConvertToMemptr( byteArray AS "System.Byte[]" ):
DEFINE VARIABLE encodedText AS LONGCHAR NO-UNDO.
encodedText = System.Convert:ToBase64String (byteArray).
aMEMPTR = BASE64-DECODE(encodedText).
RETURN aMEMPTR.
END METHOD.
--------------------------------------------------------------------------------------
/* METHOD 3 MEMPTR to System.Byte[] works and tested.
Reverse conversion method 2 does not work, why? */
METHOD PUBLIC STATIC "System.Byte[]" ConvertToByteArray( memPointer AS MEMPTR ):
DEFINE VARIABLE encodedText AS LONGCHAR NO-UNDO.
encodedText = BASE64-ENCODE (memPointer).
RETURN System.Convert:FromBase64String (encodedText).
END METHOD.