this routine encodes a single variable of type int8 into base64 format
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=c_int_least8_t), | intent(in), | target | :: | indata |
data to be encoded |
|
integer, | intent(in) | :: | outfile |
output file unit |
subroutine int8_to_base64_single( indata, outfile )
! ---------------------------------------------------------------------------
!> data to be encoded
integer(kind=c_int_least8_t), target, intent(in) :: indata
!> output file unit
integer, intent(in) :: outfile
! ---------------------------------------------------------------------------
integer(kind=c_int) :: baserc
integer(kind=c_int) :: insize, outsize, ipindex, min_iplen
integer :: ind
type(c_ptr) :: base64_out
type(c_ptr) :: base64_in
type(c_ptr) :: encoder_in
character, target :: base64_string(encoderlen), encoder_str(encoderblocklen)
! ---------------------------------------------------------------------------
base64_in = c_loc(indata)
insize = int(c_sizeof(indata), kind=4)
outsize = ceiling(insize/3._rk)*4
base64_out = c_loc(base64_string)
encoder_in = c_loc(encoder_str)
ipindex = 0
do
do ind = 0, 2
baserc = encodeindex( base64_in, encoder_in, insize, ind, ipindex )
ipindex = ipindex + 1
end do
min_iplen = min(insize - ipindex + 3, 3)
baserc = encodeblock( encoder_in, base64_out, min_iplen, outsize )
write(outfile) base64_string
if (ipindex >= insize) exit
end do
end subroutine int8_to_base64_single