
This commit includes updates that affects the build, testing, and deployment of Tile38. - The root level build.sh has been broken up into multiple scripts and placed in the "scripts" directory. - The vendor directory has been updated to follow the Go modules rules, thus `make` should work on isolated environments. Also some vendored packages may have been updated to a later version, if needed. - The Makefile has been updated to allow for making single binaries such as `make tile38-server`. There is some scaffolding during the build process, so from now on all binaries should be made using make. For example, to run a development version of the tile38-cli binary, do this: make tile38-cli && ./tile38-cli not this: go run cmd/tile38-cli/main.go - Travis.CI docker push script has been updated to address a change to Docker's JSON repo meta output, which in turn fixes a bug where new Tile38 versions were not being properly pushed to Docker
90 lines
1.8 KiB
Go
90 lines
1.8 KiB
Go
package sarama
|
|
|
|
type MessageBlock struct {
|
|
Offset int64
|
|
Msg *Message
|
|
}
|
|
|
|
// Messages convenience helper which returns either all the
|
|
// messages that are wrapped in this block
|
|
func (msb *MessageBlock) Messages() []*MessageBlock {
|
|
if msb.Msg.Set != nil {
|
|
return msb.Msg.Set.Messages
|
|
}
|
|
return []*MessageBlock{msb}
|
|
}
|
|
|
|
func (msb *MessageBlock) encode(pe packetEncoder) error {
|
|
pe.putInt64(msb.Offset)
|
|
pe.push(&lengthField{})
|
|
err := msb.Msg.encode(pe)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return pe.pop()
|
|
}
|
|
|
|
func (msb *MessageBlock) decode(pd packetDecoder) (err error) {
|
|
if msb.Offset, err = pd.getInt64(); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err = pd.push(&lengthField{}); err != nil {
|
|
return err
|
|
}
|
|
|
|
msb.Msg = new(Message)
|
|
if err = msb.Msg.decode(pd); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err = pd.pop(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type MessageSet struct {
|
|
PartialTrailingMessage bool // whether the set on the wire contained an incomplete trailing MessageBlock
|
|
Messages []*MessageBlock
|
|
}
|
|
|
|
func (ms *MessageSet) encode(pe packetEncoder) error {
|
|
for i := range ms.Messages {
|
|
err := ms.Messages[i].encode(pe)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (ms *MessageSet) decode(pd packetDecoder) (err error) {
|
|
ms.Messages = nil
|
|
|
|
for pd.remaining() > 0 {
|
|
msb := new(MessageBlock)
|
|
err = msb.decode(pd)
|
|
switch err {
|
|
case nil:
|
|
ms.Messages = append(ms.Messages, msb)
|
|
case ErrInsufficientData:
|
|
// As an optimization the server is allowed to return a partial message at the
|
|
// end of the message set. Clients should handle this case. So we just ignore such things.
|
|
ms.PartialTrailingMessage = true
|
|
return nil
|
|
default:
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (ms *MessageSet) addMessage(msg *Message) {
|
|
block := new(MessageBlock)
|
|
block.Msg = msg
|
|
ms.Messages = append(ms.Messages, block)
|
|
}
|