Skip to content

Instantly share code, notes, and snippets.

@xaviershay
Created November 29, 2009 01:42
Show Gist options
  • Save xaviershay/244738 to your computer and use it in GitHub Desktop.
Save xaviershay/244738 to your computer and use it in GitHub Desktop.
; AMQP 0.9.1, correct ABNF format, with circular dependencies excluded for the moment (so it's
; technically incomplete, but functionally I think will deal with most messages I'm interested in)
amqp = protocol-header *amqp-unit
amqp-unit = method / content / heartbeat ; amqp-unit was not defined in the spec
protocol-header = literal-AMQP protocol-id protocol-version
literal-AMQP = %d65.77.81.80 ; "AMQP"
protocol-id = %d0 ; Must be 0
protocol-version = %d0.9.1 ; 0-9-1
method = method-frame [ content ]
method-frame = %d1 frame-properties method-payload frame-end
frame-properties = channel payload-size
channel = short-uint ; Non-zero
payload-size = long-uint
method-payload = class-id method-id *amqp-field
class-id = %x0001-FFFF ; Changed the formatting of these constants to match the RFC
method-id = %x0001-FFFF
amqp-field = BIT / OCTET
/ short-uint / long-uint / long-long-uint
/ short-string / long-string
/ timestamp
/ field-table
short-short-int = OCTET
short-short-uint = OCTET
short-int = 2*OCTET
long-int = 4*OCTET
long-long-int = 8*OCTET
float = 4*OCTET ; IEEE-754
double = 8*OCTET ; rfc1832 XDR double
boolean = OCTET ; 0 = FALSE, else TRUE
short-uint = 2*OCTET
long-uint = 4*OCTET
long-long-uint = 8*OCTET
short-string = OCTET *string-char ; length + content
string-char = OCTET ; %x01 .. %xFF
long-string = long-uint *OCTET ; length + content
timestamp = long-long-uint ; 64-bit POSIX
field-table = long-uint *field-value-pair
field-value-pair = field-name field-value
field-name = short-string
field-value = "t" boolean ; Needed to use " here rather than '
/ "b" short-short-int
/ "B" short-short-uint
/ "U" short-int
/ "u" short-uint
/ "I" long-int
/ "i" long-uint
/ "L" long-long-int
/ "l" long-long-uint
/ "f" float
/ "d" double
/ "D" decimal-value
/ "s" short-string
/ "S" long-string
; / "A" field-array ; Circular dependency
/ "T" timestamp
; / "F" field-table ; Circular dependency
/ "V" ; no field
decimal-value = scale long-uint
scale = OCTET ; number of decimal digits
field-array = long-int *field-value ; array of values
frame-end = %xCE
content = %d2 content-header *content-body
content-header = frame-properties header-payload frame-end
header-payload = content-class content-weight content-body-size
property-flags property-list
content-class = OCTET
content-weight = %x00
content-body-size = long-long-uint
property-flags = 15*BIT %b0 / 15*BIT %b1 property-flags
property-list = *amqp-field
content-body = %d3 frame-properties body-payload frame-end
body-payload = *OCTET
heartbeat = %d8 %d0 %d0 frame-end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment