changeset 498:4cfe4991ee63 onclient

Use the prompt characters from mapi_prompt.h Instead of PROMPT = "." and MORE = "," we now have PROMPT = "\001\001", MORE = "\001\002" and FILETRANSFER = "\001\003".
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Fri, 13 Aug 2021 11:57:56 +0200 (2021-08-13)
parents aed7f32e029a
children 71d8ce4c3ac0
files src/main/java/org/monetdb/mcl/io/BufferedMCLReader.java src/main/java/org/monetdb/mcl/io/LineType.java src/main/java/org/monetdb/mcl/net/MapiSocket.java
diffstat 3 files changed, 88 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/monetdb/mcl/io/BufferedMCLReader.java
+++ b/src/main/java/org/monetdb/mcl/io/BufferedMCLReader.java
@@ -104,39 +104,7 @@ public final class BufferedMCLReader ext
 	 * @param line the string to examine
 	 */
 	public void setLineType(final String line) {
-		if (line == null || line.isEmpty()) {
-			lineType = UNKNOWN;
-			return;
-		}
-		switch (line.charAt(0)) {
-			case '.':
-				lineType = PROMPT;
-				break;
-			case ',':
-				lineType = MORE;
-				break;
-			case '[':	/* multi field result */
-			case '=':	/* single value result */
-				lineType = RESULT;
-				break;
-			case '%':
-				lineType = HEADER;
-				break;
-			case '&':
-				lineType = SOHEADER;
-				break;
-			case '#':
-				lineType = INFO;
-				break;
-			case '!':
-				lineType = ERROR;
-				break;
-			case '^':
-				lineType = REDIRECT;
-				break;
-			default:
-				lineType = UNKNOWN;
-		}
+		lineType = LineType.classify(line);
 	}
 
 	/**
--- a/src/main/java/org/monetdb/mcl/io/LineType.java
+++ b/src/main/java/org/monetdb/mcl/io/LineType.java
@@ -2,31 +2,101 @@ package org.monetdb.mcl.io;
 
 public enum LineType {
 	/** "there is currently no line", or the the type is unknown is represented by UNKNOWN */
-	UNKNOWN(0),
+	UNKNOWN(null),
+
 	/** a line starting with ! indicates ERROR */
-	ERROR('!'),
+	ERROR(new byte[] { '!' }),
+
 	/** a line starting with % indicates HEADER */
-	HEADER('%'),
+	HEADER(new byte[] { '%' }),
+
 	/** a line starting with [ indicates RESULT */
-	RESULT('['),
+	RESULT(new byte[] { '[' }),
+
 	/** a line which matches the pattern of prompt1 is a PROMPT */
-	PROMPT('.'),
+	PROMPT(new byte[] { 1, 1 }),
+
 	/** a line which matches the pattern of prompt2 is a MORE */
-	MORE(','),
+	MORE(new byte[] { 1, 2 }),
+
+	/** a line which matches the pattern of prompt3 is a FILETRANSFER */
+	FILETRANSFER(new byte[] { 1, 3 }),
+
 	/** a line starting with &amp; indicates the start of a header block */
-	SOHEADER('&'),
+	SOHEADER(new byte[] { '&' }),
+
 	/** a line starting with ^ indicates REDIRECT */
-	REDIRECT('^'),
+	REDIRECT(new byte[] { '^' }),
+
 	/** a line starting with # indicates INFO */
-	INFO('#');
+	INFO(new byte[] { '#' });
+
+	private final byte[] bytes;
 
-	private final byte chr;
+	LineType(byte[] bytes) {
+		this.bytes = bytes;
+	}
 
-	LineType(int chr) {
-		this.chr = (byte) chr;
+	public final byte[] bytes() {
+		return this.bytes;
 	}
 
-	public byte chr() {
-		return this.chr;
+	public static final LineType classify(String line) {
+		if (line == null) {
+			return UNKNOWN;
+		}
+		if (line.length() > 1) {
+			return classify(line.charAt(0), line.charAt(1));
+		} else if (line.length() == 1) {
+			return classify(line.charAt(0), 0);
+		} else {
+			return UNKNOWN;
+		}
+	}
+
+	public static final LineType classify(byte[] line) {
+		if (line == null) {
+			return UNKNOWN;
+		}
+		if (line.length > 1) {
+			return classify(line[0], line[1]);
+		} else if (line.length == 1) {
+			return classify(line[0], 0);
+		} else {
+			return UNKNOWN;
+		}
+	}
+
+	private static final LineType classify(int ch0, int ch1) {
+		switch (ch0) {
+			case '!':
+				return ERROR;
+			case '%':
+				return HEADER;
+			case '[':
+				return RESULT;
+			case '&':
+				return SOHEADER;
+			case '^':
+				return REDIRECT;
+			case '#':
+				return INFO;
+			case 1:
+				// prompts, see below
+				break;
+			default:
+				return UNKNOWN;
+		}
+
+		switch (ch1) {
+			case 1:
+				return PROMPT;
+			case 2:
+				return MORE;
+			case 3:
+				return FILETRANSFER;
+			default:
+				return UNKNOWN;
+		}
 	}
 }
--- a/src/main/java/org/monetdb/mcl/net/MapiSocket.java
+++ b/src/main/java/org/monetdb/mcl/net/MapiSocket.java
@@ -985,7 +985,9 @@ public class MapiSocket {	/* cannot (yet
 					block[blockLen++] = '\n';
 				}
 				// insert 'fake' flush
-				block[blockLen++] = LineType.PROMPT.chr();
+				for (byte b: LineType.PROMPT.bytes()) {
+					block[blockLen++] = b;
+				}
 				block[blockLen++] = '\n';
 				if (debug)
 					log("RD ", "inserting prompt", true);