Skip to content

Instantly share code, notes, and snippets.

@GavinRay97
Created December 23, 2022 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GavinRay97/f3113885f80d0425b90dade79ce08d80 to your computer and use it in GitHub Desktop.
Save GavinRay97/f3113885f80d0425b90dade79ce08d80 to your computer and use it in GitHub Desktop.
Autogenerated PG Wire Protocol code example
// Generated by blah blah blah
public class PostgresTypes {
public static class Backend {
public static class AuthenticationOk {
/** Identifies the message as an authentication request. */
byte field1_Byte1 = 'R';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 8;
/** Specifies that the authentication was successful. */
int field3_Int32;
}
public static class AuthenticationKerberosV5 {
/** Identifies the message as an authentication request. */
byte field1_Byte1 = 'R';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 8;
/** Specifies that Kerberos V5 authentication is required. */
int field3_Int32 = 2;
}
public static class AuthenticationCleartextPassword {
/** Identifies the message as an authentication request. */
byte field1_Byte1 = 'R';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 8;
/** Specifies that a clear-text password is required. */
int field3_Int32 = 3;
}
public static class AuthenticationMD5Password {
/** Identifies the message as an authentication request. */
byte field1_Byte1 = 'R';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 12;
/** Specifies that an MD5-encrypted password is required. */
int field3_Int32 = 5;
/** The salt to use when encrypting the password. */
byte[] /* Byte4 */ field4_Byte4;
}
public static class AuthenticationSCMCredential {
/** Identifies the message as an authentication request. */
byte field1_Byte1 = 'R';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 8;
/** Specifies that an SCM credentials message is required. */
int field3_Int32 = 6;
}
public static class AuthenticationGSS {
/** Identifies the message as an authentication request. */
byte field1_Byte1 = 'R';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 8;
/** Specifies that GSSAPI authentication is required. */
int field3_Int32 = 7;
}
public static class AuthenticationGSSContinue {
/** Identifies the message as an authentication request. */
byte field1_Byte1 = 'R';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** Specifies that this message contains GSSAPI or SSPI data. */
int field3_Int32 = 8;
/** GSSAPI or SSPI authentication data. */
byte[] /* Byten */ field4_Byten;
}
public static class AuthenticationSSPI {
/** Identifies the message as an authentication request. */
byte field1_Byte1 = 'R';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 8;
/** Specifies that SSPI authentication is required. */
int field3_Int32 = 9;
}
public static class AuthenticationSASL {
/** Identifies the message as an authentication request. */
byte field1_Byte1 = 'R';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** Specifies that SASL authentication is required.The message body is a list of SASL authentication mechanisms, in the server's order of preference. A zero byte is required as terminator after the last authentication mechanism name. For each mechanism, there is the following: */
int field3_Int32 = 10;
/** Name of a SASL authentication mechanism. */
byte[] /* Null-terminated */ field4_String;
}
public static class AuthenticationSASLContinue {
/** Identifies the message as an authentication request. */
byte field1_Byte1 = 'R';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** Specifies that this message contains a SASL challenge. */
int field3_Int32 = 11;
/** SASL data, specific to the SASL mechanism being used. */
byte[] /* Byten */ field4_Byten;
}
public static class AuthenticationSASLFinal {
/** Identifies the message as an authentication request. */
byte field1_Byte1 = 'R';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** Specifies that SASL authentication has completed. */
int field3_Int32 = 12;
/** SASL outcome "additional data", specific to the SASL mechanism being used. */
byte[] /* Byten */ field4_Byten;
}
public static class BackendKeyData {
/** Identifies the message as cancellation key data. The frontend must save these values if it wishes to be able to issue CancelRequest messages later. */
byte field1_Byte1 = 'K';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 12;
/** The process ID of this backend. */
int field3_Int32;
/** The secret key of this backend. */
int field4_Int32;
}
public static class BindComplete {
/** Identifies the message as a Bind-complete indicator. */
byte field1_Byte1 = '2';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 4;
}
public static class CloseComplete {
/** Identifies the message as a Close-complete indicator. */
byte field1_Byte1 = '3';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 4;
}
public static class CommandComplete {
/** Identifies the message as a command-completed response. */
byte field1_Byte1 = 'C';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** The command tag. This is usually a single word that identifies which SQL command was completed.For an INSERT command, the tag is INSERT oid rows, where rows is the number of rows inserted. oid used to be the object ID of the inserted row if rows was 1 and the target table had OIDs, but OIDs system columns are not supported anymore; therefore oid is always 0.For a DELETE command, the tag is DELETE rows where rows is the number of rows deleted.For an UPDATE command, the tag is UPDATE rows where rows is the number of rows updated.For a SELECT or CREATE TABLE AS command, the tag is SELECT rows where rows is the number of rows retrieved.For a MOVE command, the tag is MOVE rows where rows is the number of rows the cursor's position has been changed by.For a FETCH command, the tag is FETCH rows where rows is the number of rows that have been retrieved from the cursor.For a COPY command, the tag is COPY rows where rows is the number of rows copied. (Note: the row count appears only in PostgreSQL 8.2 and later.)CopyData (F & B) */
byte[] /* Null-terminated */ field3_String;
/** Identifies the message as COPY data. */
byte field4_Byte1 = 'd';
/** Length of message contents in bytes, including self. */
int field5_Int32;
/** Data that forms part of a COPY data stream. Messages sent from the backend will always correspond to single data rows, but messages sent by frontends might divide the data stream arbitrarily.CopyDone (F & B) */
byte[] /* Byten */ field6_Byten;
/** Identifies the message as a COPY-complete indicator. */
byte field7_Byte1 = 'c';
/** Length of message contents in bytes, including self. */
int field8_Int32 = 4;
}
public static class CopyInResponse {
/** Identifies the message as a Start Copy In response. The frontend must now send copy-in data (if not prepared to do so, send a CopyFail message). */
byte field1_Byte1 = 'G';
/** Length of message contents in bytes, including self.Int80 indicates the overall COPY format is textual (rows separated by newlines, columns separated by separator characters, etc.). 1 indicates the overall copy format is binary (similar to DataRow format). See COPY for more information. */
int field2_Int32;
/** The number of columns in the data to be copied (denoted N below). */
short field3_Int16;
/** The format codes to be used for each column. Each must presently be zero (text) or one (binary). All must be zero if the overall copy format is textual. */
short field4_Int16 /* N */;
}
public static class CopyOutResponse {
/** Identifies the message as a Start Copy Out response. This message will be followed by copy-out data. */
byte field1_Byte1 = 'H';
/** Length of message contents in bytes, including self.Int80 indicates the overall COPY format is textual (rows separated by newlines, columns separated by separator characters, etc.). 1 indicates the overall copy format is binary (similar to DataRow format). See COPY for more information. */
int field2_Int32;
/** The number of columns in the data to be copied (denoted N below). */
short field3_Int16;
/** The format codes to be used for each column. Each must presently be zero (text) or one (binary). All must be zero if the overall copy format is textual. */
short field4_Int16 /* N */;
}
public static class CopyBothResponse {
/** Identifies the message as a Start Copy Both response. This message is used only for Streaming Replication. */
byte field1_Byte1 = 'W';
/** Length of message contents in bytes, including self.Int80 indicates the overall COPY format is textual (rows separated by newlines, columns separated by separator characters, etc.). 1 indicates the overall copy format is binary (similar to DataRow format). See COPY for more information. */
int field2_Int32;
/** The number of columns in the data to be copied (denoted N below). */
short field3_Int16;
/** The format codes to be used for each column. Each must presently be zero (text) or one (binary). All must be zero if the overall copy format is textual. */
short field4_Int16 /* N */;
}
public static class DataRow {
/** Identifies the message as a data row. */
byte field1_Byte1 = 'D';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** The number of column values that follow (possibly zero).Next, the following pair of fields appear for each column: */
short field3_Int16;
/** The length of the column value, in bytes (this count does not include itself). Can be zero. As a special case, -1 indicates a NULL column value. No value bytes follow in the NULL case. */
int field4_Int32;
/** The value of the column, in the format indicated by the associated format code. n is the above length. */
byte[] /* Byten */ field5_Byten;
}
public static class EmptyQueryResponse {
/** Identifies the message as a response to an empty query string. (This substitutes for CommandComplete.) */
byte field1_Byte1 = 'I';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 4;
}
public static class ErrorResponse {
/** Identifies the message as an error. */
byte field1_Byte1 = 'E';
/** Length of message contents in bytes, including self.The message body consists of one or more identified fields, followed by a zero byte as a terminator. Fields can appear in any order. For each field there is the following: */
int field2_Int32;
/** A code identifying the field type; if zero, this is the message terminator and no string follows. The presently defined field types are listed in Section 55.8. Since more field types might be added in future, frontends should silently ignore fields of unrecognized type. */
byte field3_Byte1;
/** The field value. */
byte[] /* Null-terminated */ field4_String;
}
public static class FunctionCallResponse {
/** Identifies the message as a function call result. */
byte field1_Byte1 = 'V';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** The length of the function result value, in bytes (this count does not include itself). Can be zero. As a special case, -1 indicates a NULL function result. No value bytes follow in the NULL case. */
int field3_Int32;
/** The value of the function result, in the format indicated by the associated format code. n is the above length. */
byte[] /* Byten */ field4_Byten;
}
public static class NegotiateProtocolVersion {
/** Identifies the message as a protocol version negotiation message. */
byte field1_Byte1 = 'v';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** Newest minor protocol version supported by the server for the major protocol version requested by the client. */
int field3_Int32;
/** Number of protocol options not recognized by the server.Then, for protocol option not recognized by the server, there is the following: */
int field4_Int32;
/** The option name. */
byte[] /* Null-terminated */ field5_String;
}
public static class NoData {
/** Identifies the message as a no-data indicator. */
byte field1_Byte1 = 'n';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 4;
}
public static class NoticeResponse {
/** Identifies the message as a notice. */
byte field1_Byte1 = 'N';
/** Length of message contents in bytes, including self.The message body consists of one or more identified fields, followed by a zero byte as a terminator. Fields can appear in any order. For each field there is the following: */
int field2_Int32;
/** A code identifying the field type; if zero, this is the message terminator and no string follows. The presently defined field types are listed in Section 55.8. Since more field types might be added in future, frontends should silently ignore fields of unrecognized type. */
byte field3_Byte1;
/** The field value. */
byte[] /* Null-terminated */ field4_String;
}
public static class NotificationResponse {
/** Identifies the message as a notification response. */
byte field1_Byte1 = 'A';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** The process ID of the notifying backend process. */
int field3_Int32;
/** The name of the channel that the notify has been raised on. */
byte[] /* Null-terminated */ field4_String;
/** The “payload” string passed from the notifying process. */
byte[] /* Null-terminated */ field5_String;
}
public static class ParameterDescription {
/** Identifies the message as a parameter description. */
byte field1_Byte1 = 't';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** The number of parameters used by the statement (can be zero).Then, for each parameter, there is the following: */
short field3_Int16;
/** Specifies the object ID of the parameter data type. */
int field4_Int32;
}
public static class ParameterStatus {
/** Identifies the message as a run-time parameter status report. */
byte field1_Byte1 = 'S';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** The name of the run-time parameter being reported. */
byte[] /* Null-terminated */ field3_String;
/** The current value of the parameter. */
byte[] /* Null-terminated */ field4_String;
}
public static class ParseComplete {
/** Identifies the message as a Parse-complete indicator. */
byte field1_Byte1 = '1';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 4;
}
public static class PortalSuspended {
/** Identifies the message as a portal-suspended indicator. Note this only appears if an Execute message's row-count limit was reached. */
byte field1_Byte1 = 's';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 4;
}
public static class ReadyForQuery {
/** Identifies the message type. ReadyForQuery is sent whenever the backend is ready for a new query cycle. */
byte field1_Byte1 = 'Z';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 5;
/** Current backend transaction status indicator. Possible values are 'I' if idle (not in a transaction block); 'T' if in a transaction block; or 'E' if in a failed transaction block (queries will be rejected until block is ended). */
byte field3_Byte1;
}
public static class RowDescription {
/** Identifies the message as a row description. */
byte field1_Byte1 = 'T';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** Specifies the number of fields in a row (can be zero).Then, for each field, there is the following: */
short field3_Int16;
/** The field name. */
byte[] /* Null-terminated */ field4_String;
/** If the field can be identified as a column of a specific table, the object ID of the table; otherwise zero. */
int field5_Int32;
/** If the field can be identified as a column of a specific table, the attribute number of the column; otherwise zero. */
short field6_Int16;
/** The object ID of the field's data type. */
int field7_Int32;
/** The data type size (see pg_type.typlen). Note that negative values denote variable-width types. */
short field8_Int16;
/** The type modifier (see pg_attribute.atttypmod). The meaning of the modifier is type-specific. */
int field9_Int32;
/** The format code being used for the field. Currently will be zero (text) or one (binary). In a RowDescription returned from the statement variant of Describe, the format code is not yet known and will always be zero. */
short field10_Int16;
}
}
public static class Frontend {
public static class Bind {
/** Identifies the message as a Bind command. */
byte field1_Byte1 = 'B';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** The name of the destination portal (an empty string selects the unnamed portal). */
byte[] /* Null-terminated */ field3_String;
/** The name of the source prepared statement (an empty string selects the unnamed prepared statement). */
byte[] /* Null-terminated */ field4_String;
/** The number of parameter format codes that follow (denoted C below). This can be zero to indicate that there are no parameters or that the parameters all use the default format (text); or one, in which case the specified format code is applied to all parameters; or it can equal the actual number of parameters. */
short field5_Int16;
/** The parameter format codes. Each must presently be zero (text) or one (binary). */
short field6_Int16 /* C */;
/** The number of parameter values that follow (possibly zero). This must match the number of parameters needed by the query.Next, the following pair of fields appear for each parameter: */
short field7_Int16;
/** The length of the parameter value, in bytes (this count does not include itself). Can be zero. As a special case, -1 indicates a NULL parameter value. No value bytes follow in the NULL case. */
int field8_Int32;
/** The value of the parameter, in the format indicated by the associated format code. n is the above length.After the last parameter, the following fields appear: */
byte[] /* Byten */ field9_Byten;
/** The number of result-column format codes that follow (denoted R below). This can be zero to indicate that there are no result columns or that the result columns should all use the default format (text); or one, in which case the specified format code is applied to all result columns (if any); or it can equal the actual number of result columns of the query. */
short field10_Int16;
/** The result-column format codes. Each must presently be zero (text) or one (binary). */
short field11_Int16 /* R */;
}
public static class CancelRequest {
/** Length of message contents in bytes, including self. */
int field1_Int32 = 16;
/** The cancel request code. The value is chosen to contain 1234 in the most significant 16 bits, and 5678 in the least significant 16 bits. (To avoid confusion, this code must not be the same as any protocol version number.) */
int field2_Int32 = 80877102;
/** The process ID of the target backend. */
int field3_Int32;
/** The secret key for the target backend. */
int field4_Int32;
}
public static class Close {
/** Identifies the message as a Close command. */
byte field1_Byte1 = 'C';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** 'S' to close a prepared statement; or 'P' to close a portal. */
byte field3_Byte1;
/** The name of the prepared statement or portal to close (an empty string selects the unnamed prepared statement or portal). */
byte[] /* Null-terminated */ field4_String;
}
public static class CopyFail {
/** Identifies the message as a COPY-failure indicator. */
byte field1_Byte1 = 'f';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** An error message to report as the cause of failure. */
byte[] /* Null-terminated */ field3_String;
}
public static class Describe {
/** Identifies the message as a Describe command. */
byte field1_Byte1 = 'D';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** 'S' to describe a prepared statement; or 'P' to describe a portal. */
byte field3_Byte1;
/** The name of the prepared statement or portal to describe (an empty string selects the unnamed prepared statement or portal). */
byte[] /* Null-terminated */ field4_String;
}
public static class Execute {
/** Identifies the message as an Execute command. */
byte field1_Byte1 = 'E';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** The name of the portal to execute (an empty string selects the unnamed portal). */
byte[] /* Null-terminated */ field3_String;
/** Maximum number of rows to return, if portal contains a query that returns rows (ignored otherwise). Zero denotes “no limit”. */
int field4_Int32;
}
public static class Flush {
/** Identifies the message as a Flush command. */
byte field1_Byte1 = 'H';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 4;
}
public static class FunctionCall {
/** Identifies the message as a function call. */
byte field1_Byte1 = 'F';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** Specifies the object ID of the function to call. */
int field3_Int32;
/** The number of argument format codes that follow (denoted C below). This can be zero to indicate that there are no arguments or that the arguments all use the default format (text); or one, in which case the specified format code is applied to all arguments; or it can equal the actual number of arguments. */
short field4_Int16;
/** The argument format codes. Each must presently be zero (text) or one (binary). */
short field5_Int16 /* C */;
/** Specifies the number of arguments being supplied to the function.Next, the following pair of fields appear for each argument: */
short field6_Int16;
/** The length of the argument value, in bytes (this count does not include itself). Can be zero. As a special case, -1 indicates a NULL argument value. No value bytes follow in the NULL case. */
int field7_Int32;
/** The value of the argument, in the format indicated by the associated format code. n is the above length.After the last argument, the following field appears: */
byte[] /* Byten */ field8_Byten;
/** The format code for the function result. Must presently be zero (text) or one (binary). */
short field9_Int16;
}
public static class GSSENCRequest {
/** Length of message contents in bytes, including self. */
int field1_Int32 = 8;
/** The GSSAPI Encryption request code. The value is chosen to contain 1234 in the most significant 16 bits, and 5680 in the least significant 16 bits. (To avoid confusion, this code must not be the same as any protocol version number.) */
int field2_Int32 = 80877104;
}
public static class GSSResponse {
/** Identifies the message as a GSSAPI or SSPI response. Note that this is also used for SASL and password response messages. The exact message type can be deduced from the context. */
byte field1_Byte1 = 'p';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** GSSAPI/SSPI specific message data. */
byte[] /* Byten */ field3_Byten;
}
public static class Parse {
/** Identifies the message as a Parse command. */
byte field1_Byte1 = 'P';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** The name of the destination prepared statement (an empty string selects the unnamed prepared statement). */
byte[] /* Null-terminated */ field3_String;
/** The query string to be parsed. */
byte[] /* Null-terminated */ field4_String;
/** The number of parameter data types specified (can be zero). Note that this is not an indication of the number of parameters that might appear in the query string, only the number that the frontend wants to prespecify types for.Then, for each parameter, there is the following: */
short field5_Int16;
/** Specifies the object ID of the parameter data type. Placing a zero here is equivalent to leaving the type unspecified. */
int field6_Int32;
}
public static class PasswordMessage {
/** Identifies the message as a password response. Note that this is also used for GSSAPI, SSPI and SASL response messages. The exact message type can be deduced from the context. */
byte field1_Byte1 = 'p';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** The password (encrypted, if requested). */
byte[] /* Null-terminated */ field3_String;
}
public static class Query {
/** Identifies the message as a simple query. */
byte field1_Byte1 = 'Q';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** The query string itself. */
byte[] /* Null-terminated */ field3_String;
}
public static class SASLInitialResponse {
/** Identifies the message as an initial SASL response. Note that this is also used for GSSAPI, SSPI and password response messages. The exact message type is deduced from the context. */
byte field1_Byte1 = 'p';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** Name of the SASL authentication mechanism that the client selected. */
byte[] /* Null-terminated */ field3_String;
/** Length of SASL mechanism specific "Initial Client Response" that follows, or -1 if there is no Initial Response. */
int field4_Int32;
/** SASL mechanism specific "Initial Response". */
byte[] /* Byten */ field5_Byten;
}
public static class SASLResponse {
/** Identifies the message as a SASL response. Note that this is also used for GSSAPI, SSPI and password response messages. The exact message type can be deduced from the context. */
byte field1_Byte1 = 'p';
/** Length of message contents in bytes, including self. */
int field2_Int32;
/** SASL mechanism specific message data. */
byte[] /* Byten */ field3_Byten;
}
public static class SSLRequest {
/** Length of message contents in bytes, including self. */
int field1_Int32 = 8;
/** The SSL request code. The value is chosen to contain 1234 in the most significant 16 bits, and 5679 in the least significant 16 bits. (To avoid confusion, this code must not be the same as any protocol version number.) */
int field2_Int32 = 80877103;
}
public static class StartupMessage {
/** Length of message contents in bytes, including self. */
int field1_Int32;
/** The protocol version number. The most significant 16 bits are the major version number (3 for the protocol described here). The least significant 16 bits are the minor version number (0 for the protocol described here).The protocol version number is followed by one or more pairs of parameter name and value strings. A zero byte is required as a terminator after the last name/value pair. Parameters can appear in any order. user is required, others are optional. Each parameter is specified as: */
int field2_Int32 = 196608;
/** The parameter name. Currently recognized names are:userThe database user name to connect as. Required; there is no default.databaseThe database to connect to. Defaults to the user name.optionsCommand-line arguments for the backend. (This is deprecated in favor of setting individual run-time parameters.) Spaces within this string are considered to separate arguments, unless escaped with a backslash (); write \ to represent a literal backslash.replicationUsed to connect in streaming replication mode, where a small set of replication commands can be issued instead of SQL statements. Value can be true, false, or database, and the default is false. See Section 55.4 for details.In addition to the above, other parameters may be listed. Parameter names beginning with _pq_. are reserved for use as protocol extensions, while others are treated as run-time parameters to be set at backend start time. Such settings will be applied during backend start (after parsing the command-line arguments if any) and will act as session defaults. */
byte[] /* Null-terminated */ field3_String;
/** The parameter value. */
byte[] /* Null-terminated */ field4_String;
}
public static class Sync {
/** Identifies the message as a Sync command. */
byte field1_Byte1 = 'S';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 4;
}
public static class Terminate {
/** Identifies the message as a termination. */
byte field1_Byte1 = 'X';
/** Length of message contents in bytes, including self. */
int field2_Int32 = 4;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment