Skip to content

Commit

Permalink
WIP: AMQP 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
baelter committed Nov 1, 2024
1 parent 93b79e8 commit 71537e3
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/1/protocol_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require "../spec_helper"
require "../../src/amq/protocol.cr"

describe AMQ::Protocol do
it "defines AMQP 1.0 header" do
AMQ::Protocol::PROTOCOL_START_1_0_0.to_slice.to_a.should eq "AMQP\x00\x01\x00\x00".bytes
end
end
1 change: 1 addition & 0 deletions src/amq/protocol.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ module AMQ
module Protocol
PROTOCOL_START_0_9_1 = UInt8.static_array(65, 77, 81, 80, 0, 0, 9, 1)
PROTOCOL_START_0_9 = UInt8.static_array(65, 77, 81, 80, 1, 1, 0, 9)
PROTOCOL_START_1_0_0 = UInt8.static_array(65, 77, 81, 80, 0, 1, 0, 0)
end
end
21 changes: 21 additions & 0 deletions src/amq/protocol/1/frames.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module AMQ
module Protocol
module V1
abstract struct Frame
getter bytesize : UInt32
getter doff : UInt8
getter type : UInt8
end

abstract struct AMQP < Frame
TYPE = 0_u8

getter channel : UInt16

def type : UInt8
TYPE
end
end
end
end
end
21 changes: 21 additions & 0 deletions src/amq/protocol/1/preformatives.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "./frames"
require "./types"

module AMQ
module Protocol
module V1
struct Open < AMQP
getter containerId : String
getter hostname : String
getter maxFrameSize : UInt
getter channelMax : UShort
getter maxIdleTimeout : Milliseconds
getter outGoingLocales : Array(IETFLanguageTag)
getter incomingGoingLocales : Array(IETFLanguageTag)
getter offeredCapabilities : Array(Symbol)
getter desiredCapabilities : Array(Symbol)
getter properties : Fields
end
end
end
end
22 changes: 22 additions & 0 deletions src/amq/protocol/1/types.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
alias UInt = UInt32
alias UShort = UInt16
alias Milliseconds = UInt

struct Symbol
# TODO
end

alias IETFLanguageTag = Symbol

alias Value = UInt | UShort | Milliseconds | Symbol | Array(Value) |
IETFLanguageTag | Map(Symbol, Value)

# A polymorphic mapping from distinct keys to values
struct Map(K, V)
# TODO
end

alias Fields = Map(Symbol, Value)

# A sequence of polymorphic values
alias List = Array(Value)

0 comments on commit 71537e3

Please sign in to comment.