I need to store sockets into database, gen_tcp:accept returns something like
#Port<0.5>
I can convert it to a bitstring using io_lib:format
["Port<0.5>"]
to store it into database but how do i convert it back to its original state to use it to send and receive data?
Update:
I tried term_to_binary
but mysql-otp failed to insert it so i did binary_to_list(term_to_binary(Socket))
, it inserted fine but adds extra <<194,xxx,xx...>> at the start of the binary into the database, any solutions? Why is it happening? If it doesn't add extra data i can convert it back fine using binary_to_term
.
I changed varchar to varbinary and now i can directly insert term_to_binary
into database and then reuse it using binary_to_term
.