I want to write a predicate that takes a stream and a string and writes the string length first as a 64 bit integer followed by the string as UTF8 encoded.
Is this in the right direction? Also: I cannot figure out how to turn a Prolog number into bytes (i.e. turn 2 into binary 0x10). Any tips there?
sendString(Stream, String) :- % make sure it is UTF8 encoded set_prolog_flag(encoding, utf8), % get a set of UTF8 codes from the string stringCodes(String, Codes), % Count and send the count first length(Codes, Length), ???? How to convert Length to a binary 64 bit number and send it ???? % Then send the encoded string % assuming this doesn't do anything with Codes except send them raw... write_term(Stream, Codes, ), flush_output(Stream). stringCodes(String, Codes) :- with_output_to(codes(Codes), ( current_output(Stream), % I believe this will use the set_prolog_flag(encoding) to convert % to UTF8 bytes? write(Stream, String) )).