You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Base64 is an encoding scheme to translate binary data into a set of 64 characters (the Base64 alphabet). It is often used to transfer binary data over channels which only support text. One notable use case of Base64 is in the VTK XML format.
A Fortran interface might look like:
! for T in {real, integer, logical, complex}
functionbase64_encode(data) result(str)
type(T), intent(in) ::data(..)
character(len=:), allocatable :: str
endfunctionfunctionbase64_decode(str) result(res)
character(len=*), intent(in) :: str
character(len=:), allocatable :: res ! Treated as a byte-array
endfunction
The decoding phase would need to be followed by transfer or internal I/O to recover the particular numerical type. Alternatively one could decode directly to a given type by using a mold argument to retrieve a particular type or use a generic subroutine interface.
Motivation
Base64 is an encoding scheme to translate binary data into a set of 64 characters (the Base64 alphabet). It is often used to transfer binary data over channels which only support text. One notable use case of Base64 is in the VTK XML format.
A Fortran interface might look like:
The decoding phase would need to be followed by
transfer
or internal I/O to recover the particular numerical type. Alternatively one could decode directly to a given type by using amold
argument to retrieve a particular type or use a generic subroutine interface.Prior Art
Available in multiple third-party libraries:
Also available in standard libraries of other programming languages:
matlab.net.base64encode
,matlab.net.base64decode
b64encode
,b64decode
The best third-party libraries use SIMD instructions to make the encoding/decoding fast. Details can be found in the works of Muła and Lemire (https://doi.org/10.1145/3132709, https://doi.org/10.1002/spe.2777).
Additional Information
In principle could also be exposed as a language feature: j3-fortran/fortran_proposals#330
Also encountered a wish on Stack Overflow: https://stackoverflow.com/questions/73452098/fortran-write-base64-string-of-binary-to-file
The text was updated successfully, but these errors were encountered: