Skip to content

Use InputStreamReader for serial UTF8 decoder #10389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Serial UTF-8 decoder now handles blocks of 16Kb at a time
  • Loading branch information
cmaglie committed Jun 19, 2020
commit 618eef0e0db4a3e0d35318fde4d907b73b3d37ce
8 changes: 5 additions & 3 deletions arduino-core/src/processing/app/Serial.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class Serial implements SerialPortEventListener {

private PipedOutputStream decoderInRaw;
private InputStreamReader decoderOutputUTF8;
private final int DECODER_BUFF_SIZE = 16384;

public Serial() throws SerialException {
this(PreferencesData.get("serial.port"),
Expand Down Expand Up @@ -186,10 +187,10 @@ public synchronized void serialEvent(SerialPortEvent serialEvent) {
public void processSerialEvent(byte[] buf) {
int next = 0;
int max = buf.length;
char chars[] = new char[512];
char chars[] = new char[DECODER_BUFF_SIZE];
try {
while (next < max) {
int w = Integer.min(max - next, 128);
int w = Integer.min(max - next, chars.length);
decoderInRaw.write(buf, next, w);
next += w;
int n = decoderOutputUTF8.read(chars);
Expand Down Expand Up @@ -269,7 +270,8 @@ public void setRTS(boolean state) {
public synchronized void resetDecoding(Charset charset) {
try {
decoderInRaw = new PipedOutputStream();
decoderOutputUTF8 = new InputStreamReader(new PipedInputStream(decoderInRaw), charset);
// add 16 extra bytes to make room for incomplete UTF-8 chars
decoderOutputUTF8 = new InputStreamReader(new PipedInputStream(decoderInRaw, DECODER_BUFF_SIZE + 16), charset);
} catch (IOException e) {
// Should never happen...
e.printStackTrace();
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy