Skip to content
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

NetworkInputStream #23

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ out/
/.project
/.settings/
/bin/
/target/
58 changes: 58 additions & 0 deletions deploy-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.postgresql</groupId>
<artifactId>pgsql2</artifactId>
<version>0.0.1</version>
<name>PostgreSql ADBA</name>
<description>Deploys the PostgreSql pgsql2 to OfficeFloor sourceforge for use</description>
<!-- Steps to deploy: -->
<!-- ssh -t [email protected] create -->
<!-- mvn -f deploy-pom.xml validate -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<pgsql2.version>1.0-SNAPSHOT</pgsql2.version>
</properties>
<distributionManagement>
<repository>
<id>repo.officefloor.sf.net</id>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of commits keep coming in with some of this stuff

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this is my local deployment to make the jar available for download. This is necessary for TechEmpower to access the jar for building the OfficeFloor server to use pgsql2. We should possibly consider starting to apply to release to maven central to make early adopter interest available.

<name>Maven repository on SourceForge - http://www.officefloor.net/maven2</name>
<url>scp://[email protected]:/home/frs/project/officefloor/maven/maven2</url>
</repository>
</distributionManagement>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>3.1.0</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>Upload pgsql2</id>
<phase>validate</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>${settings.localRepository}/org/postgresql/pgsql2/${pgsql2.version}/pgsql2-${pgsql2.version}.jar</file>
<repositoryId>repo.officefloor.sf.net</repositoryId>
<url>scp://[email protected]:/home/frs/project/officefloor/maven/maven2</url>
<groupId>org.postgresql</groupId>
<artifactId>pgsql2</artifactId>
<version>0.0.1</version>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
106 changes: 106 additions & 0 deletions src/main/java/org/postgresql/sql2/communication/BEFrameParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package org.postgresql.sql2.communication;

import java.io.IOException;

import org.postgresql.sql2.util.BinaryHelper;

/**
* Reads bytes from the stream from the server and produces packages on a stack
*/
public class BEFrameParser {

public static final char AUTHENTICATION = 'R';
public static final char CANCELLATION_KEY_DATA = 'K';
public static final char BIND_COMPLETE = '2';
public static final char CLOSE_COMPLETE = '3';
public static final char COMMAND_COMPLETE = 'C';
public static final char COPY_DATA = 'd';
public static final char COPY_DONE = 'c';
public static final char COPY_IN_RESPONSE = 'G';
public static final char COPY_OUT_RESPONSE = 'H';
public static final char COPY_BOTH_RESPONSE = 'W';
public static final char DATA_ROW = 'D';
public static final char EMPTY_QUERY_RESPONSE = 'I';
public static final char ERROR_RESPONSE = 'E';
public static final char FUNCTION_CALL_RESPONSE = 'V';
public static final char NEGOTIATE_PROTOCOL_VERSION = 'v';
public static final char NO_DATA = 'n';
public static final char NOTICE_RESPONSE = 'N';
public static final char NOTIFICATION_RESPONSE = 'A';
public static final char PARAM_DESCRIPTION = 't';
public static final char PARAM_STATUS = 'S';
public static final char PARSE_COMPLETE = '1';
public static final char PORTAL_SUSPENDED = 's';
public static final char READY_FOR_QUERY = 'Z';
public static final char ROW_DESCRIPTION = 'T';

private enum States {
BETWEEN, READ_TAG, READ_LEN1, READ_LEN2, READ_LEN3, READ_LEN4
}

private States state = States.BETWEEN;

private byte tag;
private byte len1;
private byte len2;
private byte len3;
private byte len4;
private int payloadLength;

public boolean parseBEFrame(NetworkInputStream inputStream) throws IOException {

// Read frame header (tag and length)
if (this.state != States.READ_LEN4) {
READ_HEADER: while (inputStream.available() > 0) {
switch (state) {
case BETWEEN:
tag = (byte) inputStream.read();
state = States.READ_TAG;
break;
case READ_TAG:
len1 = (byte) inputStream.read();
state = States.READ_LEN1;
break;
case READ_LEN1:
len2 = (byte) inputStream.read();
state = States.READ_LEN2;
break;
case READ_LEN2:
len3 = (byte) inputStream.read();
state = States.READ_LEN3;
break;
case READ_LEN3:
len4 = (byte) inputStream.read();
// -4 to ignore payload length
payloadLength = BinaryHelper.readInt(len1, len2, len3, len4) - 4;
state = States.READ_LEN4;
break READ_HEADER;
case READ_LEN4:
break READ_HEADER;
}
}
}

// Wait until all frame bytes available
if (this.state == States.READ_LEN4) {
if (this.payloadLength <= inputStream.available()) {

// Reset for next frame
this.state = States.BETWEEN;
return true;
}
}

// As here, buffer underflow
return false;
}

public char getTag() {
return (char) this.tag;
}

public int getPayloadLength() {
return this.payloadLength;
}

}
67 changes: 0 additions & 67 deletions src/main/java/org/postgresql/sql2/communication/BeFrame.java

This file was deleted.

97 changes: 0 additions & 97 deletions src/main/java/org/postgresql/sql2/communication/BeFrameParser.java

This file was deleted.

Loading