Permalink
Browse files

checkpoint

  • Loading branch information...
jeffjenkins committed Sep 21, 2015
1 parent cf13a52 commit b66a3574d6c9beeb9d02e769459ed05be27c0e46
Showing with 4,042 additions and 667 deletions.
  1. +2,830 −0 amqp-0-9-1.xml
  2. +41 −59 amqp/amqpreader.go
  3. +23 −24 amqp/amqpwriter.go
  4. +1 −0 amqp/constants_generated.go
  5. +32 −0 amqp/domains_generated.go
  6. +944 −488 amqp/protocol_generated.go
  7. +5 −0 amqp/table.go
  8. +154 −0 amqp_gen.py
  9. +0 −88 server/constants.go
  10. +12 −8 server/mq.go
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -4,12 +4,11 @@ import (
"encoding/binary"
"io"
"errors"
"bytes"
)
// Constants
func ReadProtocolHeader(buf io.Reader) error {
func ReadProtocolHeader(buf io.Reader) (err error) {
var expected = [...]byte {'A', 'M', 'Q', 'P', 0, 0, 9, 1}
var proto [8]byte
err = binary.Read(buf, binary.BigEndian, proto)
@@ -19,8 +18,8 @@ func ReadProtocolHeader(buf io.Reader) error {
return nil
}
func ReadVersion(buf io.Reader) error {
expected = [2]byte {0, 9}
func ReadVersion(buf io.Reader) (err error) {
var expected = [2]byte {0, 9}
var version [2]byte
err = binary.Read(buf, binary.BigEndian, &version)
if err != nil || version != expected {
@@ -29,7 +28,7 @@ func ReadVersion(buf io.Reader) error {
return nil
}
func ReadFrameEnd(buf io.Reader) error {
func ReadFrameEnd(buf io.Reader) (err error) {
var end byte
err = binary.Read(buf, binary.BigEndian, &end)
if err != nil || end != byte(0xCE) {
@@ -40,110 +39,93 @@ func ReadFrameEnd(buf io.Reader) error {
// Composite Types
func ReadFrameHeader(buf io.Reader) byte, uint16, uint32, error {
var channel uint16
var payloadSize uint32
var frameType byte
func ReadFrameHeader(buf io.Reader) (frameType byte, channel uint16, payloadSize uint32, err error) {
binary.Read(buf, binary.BigEndian, &frameType)
binary.Read(buf, binary.BigEndian, &channel)
binary.Read(buf, binary.BigEndian, &payloadSize)
return frameType, channel, payloadSize, nil
}
func ReadMethodPayloadHeader(buf io.Reader) uint16, uint16, error {
var classId uint16
var methodId uint16
func ReadMethodPayloadHeader(buf io.Reader) (classId uint16, methodId uint16, err error) {
binary.Read(buf, binary.BigEndian, &classId)
binary.Read(buf, binary.BigEndian, &methodId)
return
}
// Fields
func ReadBits(buf io.Reader) []bool, error{
func ReadBit(buf io.Reader) (bool, error) {
panic("Not implemented!")
}
func ReadOctet(buf io.Reader) byte, error {
var in byte
err = binary.Read(buf, binary.BigEndian, &in)
func ReadOctet(buf io.Reader) (data byte, err error) {
err = binary.Read(buf, binary.BigEndian, &data)
if err != nil {
return nil, errors.New("Could not read byte")
return 0, errors.New("Could not read byte")
}
return in, nil
return data, nil
}
func ReadShort(buf io.Reader) uint16, error {
var in uint16
err = binary.Read(buf, binary.BigEndian, &in)
func ReadShort(buf io.Reader) (data uint16, err error) {
err = binary.Read(buf, binary.BigEndian, &data)
if err != nil {
return nil, errors.New("Could not read uint16")
return 0, errors.New("Could not read uint16")
}
return in, nil
return data, nil
}
func ReadLong(buf io.Reader) uint32, error {
var in uint32
err = binary.Read(buf, binary.BigEndian, &in)
func ReadLong(buf io.Reader) (data uint32, err error) {
err = binary.Read(buf, binary.BigEndian, &data)
if err != nil {
return nil, errors.New("Could not read uint32")
return 0, errors.New("Could not read uint32")
}
return in, nil
return data, nil
}
func ReadLongLong(buf io.Reader) uint64, error {
var in uint64
err = binary.Read(buf, binary.BigEndian, &in)
func ReadLonglong(buf io.Reader) (data uint64, err error) {
err = binary.Read(buf, binary.BigEndian, &data)
if err != nil {
return nil, errors.New("Could not read uint64")
return 0, errors.New("Could not read uint64")
}
return in, nil
return data, nil
}
func ReadStringChar(buf io.Reader) byte, error {
var in byte
err = binary.Read(buf, binary.BigEndian, &in)
func ReadStringChar(buf io.Reader) (data byte, err error) {
err = binary.Read(buf, binary.BigEndian, &data)
if err != nil {
return nil, errors.New("Could not read byte")
return 0, errors.New("Could not read byte")
}
return in, nil
return data, nil
}
func ReadShortString(buf io.Reader) string, error {
func ReadShortstr(buf io.Reader) (string, error) {
var length uint8
err = binary.Read(buf, binary.BigEndian, &length)
binary.Read(buf, binary.BigEndian, &length)
if length > MaxShortStringLength {
return nil, errors.New("String too long for short string")
return "", errors.New("String too long for short string")
}
var slice = new([]byte, length)
var slice = make([]byte, 0, length)
binary.Read(buf, binary.BigEndian, slice)
return string(slice), nil
}
func ReadLongString(buf io.Reader) []byte, error {
func ReadLongstr(buf io.Reader) ([]byte, error) {
var length uint32
err = binary.Read(buf, binary.BigEndian, &length)
if length > MaxShortStringLength {
return nil, errors.New("String too long for short string")
}
var slice = new([]byte, length)
var err = binary.Read(buf, binary.BigEndian, &length)
var slice = make([]byte, 0, length)
binary.Read(buf, binary.BigEndian, slice)
return slice
return slice, err
}
func ReadTimestamp(buf io.Reader) uint64, error {
var in uint64
err = binary.Read(buf, binary.BigEndian, &in)
func ReadTimestamp(buf io.Reader) (data uint64, err error) {
err = binary.Read(buf, binary.BigEndian, &data)
if err != nil {
return nil, errors.New("Could not read uint64")
return 0, errors.New("Could not read uint64")
}
return in, nil
return data, nil
}
func ReadTable(buf io.Reader) {
func ReadTable(buf io.Reader) (Table, error) {
panic("Not implemented")
// binary.Write(buf, binary.BigEndian, 0)
}
func ReadPeerProperties(buf io.Reader) {
ReadTable(buf)
}
View
@@ -22,32 +22,31 @@ func WriteFrameEnd(buf io.Writer) error {
// Composite Types
func WriteMethodFrameHeader(buf io.Writer, channel uint16, payloadSize uint32) (err error) {
if err := binary.Write(buf, binary.BigEndian, FrameTypeMethod); err == nil {
return
}
if err := binary.Write(buf, binary.BigEndian, channel); err == nil {
return
}
if err := binary.Write(buf, binary.BigEndian, payloadSize); err == nil {
return
}
return nil
}
// func WriteMethodFrameHeader(buf io.Writer, channel uint16, payloadSize uint32) (err error) {
// if err = binary.Write(buf, binary.BigEndian, FrameTypeMethod); err != nil {
// return
// }
// if err = binary.Write(buf, binary.BigEndian, channel); err != nil {
// return
// }
// if err = binary.Write(buf, binary.BigEndian, payloadSize); err != nil {
// return
// }
// }
func WriteMethodPayloadHeader(buf io.Writer, classId uint16, methodId uint16) (err error) {
if err := binary.Write(buf, binary.BigEndian, classId); err == nil {
if err = binary.Write(buf, binary.BigEndian, classId); err != nil {
return
}
if err := binary.Write(buf, binary.BigEndian, methodId); err == nil {
if err = binary.Write(buf, binary.BigEndian, methodId); err != nil {
return
}
return nil
}
// Fields
func WriteBits(buf io.Writer, bits []bool) err {
func WriteBit(buf io.Writer, b bool) error {
// TODO
panic("Not implemented!")
return nil
@@ -65,26 +64,26 @@ func WriteLong(buf io.Writer, i uint32) error {
return binary.Write(buf, binary.BigEndian, i)
}
func WriteLongLong(buf io.Writer, i uint64) error {
return binary.Write(buf, binary.BigEndian, )
func WriteLonglong(buf io.Writer, i uint64) error {
return binary.Write(buf, binary.BigEndian, i)
}
func WriteStringChar(buf io.Writer, b byte) error {
return binary.Write(buf, binary.BigEndian, b)
}
func WriteShortString(buf io.Writer, s string) error {
if len(s) > MaxShortStringLength {
func WriteShortstr(buf io.Writer, s string) error {
if len(s) > int(MaxShortStringLength) {
return errors.New("String too long for short string")
}
binary.Write(buf, binary.BigEndian, byte(len(s)))
return binary.Write(buf, binary.BigEndian, byte(len(s)))
}
func WriteLongString(buf io.Writer, bytes []byte) (err error) {
if err := binary.Write(buf, binary.BigEndian, uint32(len(bytes))); err == nil {
func WriteLongstr(buf io.Writer, bytes []byte) (err error) {
if err = binary.Write(buf, binary.BigEndian, uint32(len(bytes))); err != nil {
return
}
if err := binary.Write(buf, binary.BigEndian, bytes); err == nil {
if err = binary.Write(buf, binary.BigEndian, bytes); err != nil {
return
}
return nil
@@ -94,7 +93,7 @@ func WriteTimestamp(buf io.Writer, timestamp uint64) error {
return binary.Write(buf, binary.BigEndian, timestamp)
}
func WriteTable(buf io.Writer) error {
func WriteTable(buf io.Writer, t Table) error {
// TODO
return binary.Write(buf, binary.BigEndian, 0)
}
@@ -1,5 +1,6 @@
package amqp
var MaxShortStringLength uint8 = 255
var FrameMethod = 1
var FrameHeader = 2
var FrameBody = 3
View
@@ -0,0 +1,32 @@
package amqp
var ReadClassId = ReadShort
var WriteClassId = WriteShort
var ReadConsumerTag = ReadShortstr
var WriteConsumerTag = WriteShortstr
var ReadDeliveryTag = ReadLonglong
var WriteDeliveryTag = WriteLonglong
var ReadExchangeName = ReadShortstr
var WriteExchangeName = WriteShortstr
var ReadMethodId = ReadShort
var WriteMethodId = WriteShort
var ReadNoAck = ReadBit
var WriteNoAck = WriteBit
var ReadNoLocal = ReadBit
var WriteNoLocal = WriteBit
var ReadNoWait = ReadBit
var WriteNoWait = WriteBit
var ReadPath = ReadShortstr
var WritePath = WriteShortstr
var ReadPeerProperties = ReadTable
var WritePeerProperties = WriteTable
var ReadQueueName = ReadShortstr
var WriteQueueName = WriteShortstr
var ReadRedelivered = ReadBit
var WriteRedelivered = WriteBit
var ReadMessageCount = ReadLong
var WriteMessageCount = WriteLong
var ReadReplyCode = ReadShort
var WriteReplyCode = WriteShort
var ReadReplyText = ReadShortstr
var WriteReplyText = WriteShortstr
Oops, something went wrong.

0 comments on commit b66a357

Please sign in to comment.