amp-message
High level AMP Message
implementation for manipulating, encoding and decoding AMP messages in Go.
Godoc
Installation
$ go get github.com/nickpoorman/go-amp-message
Example
Encoding a message:
msg := ampmessage.New(nil)
fmt.Printf("<Bytes: %x>\n", msg.ToBytes())
msg.Push(ampmessage.NewStringArg("foo"))
msg.PushString("bar")
msg.PushString("baz")
fmt.Printf("<Bytes: %x>\n", msg.ToBytes())
jsonObj, _ := ampmessage.NewJSONArg(map[string]string{"foo": "bar"})
msg.Push(jsonObj)
fmt.Printf("<Bytes: %x>\n", msg.ToBytes())
msg.PushJSON(map[string]string{"ping": "pong"})
fmt.Printf("<Bytes: %x>\n", msg.ToBytes())
blob := []byte("beep")
msg.Push(ampmessage.NewBlobArg(blob))
msg.PushBlob([]byte("boop"))
fmt.Printf("<Bytes: %x>\n", msg.ToBytes())
Decoding a message:
msg := ampmessage.New(nil)
msg.PushString("foo")
msg.PushJSON(map[string]string{"hello": "world"})
msg.PushBlob([]byte("hello"))
other, _ := ampmessage.NewFromBytes(msg.ToBytes())
fmt.Printf("%s\n", other.Shift())
fmt.Printf("%s\n", other.Shift())
fmt.Printf("%s\n", other.Shift())
API
Godoc
ampmessage.New(nil)
Initialize an empty message.
ampmessage.NewFromBytes(bytes)
Decode the buffer
AMP message to populate the Message
.
ampmessage.New(args)
Initialize a message populated with args
.
License
MIT