Improve UTF-8 handling in avrorouter
The json_stringn function should be used instead of the json_string to allow null characters as well as non-null terminated strings to be embedded in the JSON values. The CDC example Python programs now decode the data as UTF-8 instead of ASCII.
This commit is contained in:
@ -37,7 +37,7 @@ def read_json():
|
||||
rbuf += buf
|
||||
while True:
|
||||
rbuf = rbuf.lstrip()
|
||||
data = decoder.raw_decode(rbuf.decode('ascii'))
|
||||
data = decoder.raw_decode(rbuf.decode('utf_8'))
|
||||
rbuf = rbuf[data[1]:]
|
||||
print(json.dumps(data[0]))
|
||||
except ValueError as err:
|
||||
|
||||
@ -45,7 +45,7 @@ while True:
|
||||
|
||||
while True:
|
||||
rbuf = rbuf.lstrip()
|
||||
data = decoder.raw_decode(rbuf.decode('ascii'))
|
||||
data = decoder.raw_decode(rbuf.decode('utf_8'))
|
||||
rbuf = rbuf[data[1]:]
|
||||
producer.send(topic=opts.kafka_topic, value=json.dumps(data[0]).encode())
|
||||
producer.flush()
|
||||
|
||||
@ -52,4 +52,4 @@ else:
|
||||
sock.send(bytes("QUERY-LAST-TRANSACTION".encode()))
|
||||
|
||||
response = sock.recv(1024)
|
||||
print(response.decode('ascii'))
|
||||
print(response.decode('utf_8'))
|
||||
|
||||
Reference in New Issue
Block a user