dataOut.writeInt(len);
len -= 4;
byte[] data = new byte[len];
dataIn.readFully(data, 0, len);
dataOut.write(data);
dataIn = new DataInputStream(new ByteArrayInputStream(data, 0, len));
int version = dataIn.readInt();
if (version == 80877102) {
println("CancelRequest");
println(" pid: " + dataIn.readInt());
println(" key: " + dataIn.readInt());
} else if (version == 80877103) {
println("SSLRequest");
} else {
println("StartupMessage");
println(" version " + version + " (" + (version >> 16) + "." + (version & 0xff) + ")");
while (true) {
String param = readStringNull(dataIn);
if (param.length() == 0) {
break;
}
String value = readStringNull(dataIn);
println(" param " + param + "=" + value);
}
}
} else {
int x = dataIn.read();
if (x < 0) {
println("end");
return false;
}
// System.out.println(" x=" + (char)x+" " +x);
dataOut.write(x);
int len = dataIn.readInt();
dataOut.writeInt(len);
len -= 4;
byte[] data = new byte[len];
dataIn.readFully(data, 0, len);
dataOut.write(data);
dataIn = new DataInputStream(new ByteArrayInputStream(data, 0, len));
switch (x) {
case 'B': {
println("Bind");
println(" destPortal: " + readStringNull(dataIn));
println(" prepName: " + readStringNull(dataIn));