
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
130 lines
2.3 KiB
Go
130 lines
2.3 KiB
Go
package sarama
|
|
|
|
import (
|
|
"encoding/binary"
|
|
|
|
"github.com/rcrowley/go-metrics"
|
|
)
|
|
|
|
type realEncoder struct {
|
|
raw []byte
|
|
off int
|
|
stack []pushEncoder
|
|
registry metrics.Registry
|
|
}
|
|
|
|
// primitives
|
|
|
|
func (re *realEncoder) putInt8(in int8) {
|
|
re.raw[re.off] = byte(in)
|
|
re.off++
|
|
}
|
|
|
|
func (re *realEncoder) putInt16(in int16) {
|
|
binary.BigEndian.PutUint16(re.raw[re.off:], uint16(in))
|
|
re.off += 2
|
|
}
|
|
|
|
func (re *realEncoder) putInt32(in int32) {
|
|
binary.BigEndian.PutUint32(re.raw[re.off:], uint32(in))
|
|
re.off += 4
|
|
}
|
|
|
|
func (re *realEncoder) putInt64(in int64) {
|
|
binary.BigEndian.PutUint64(re.raw[re.off:], uint64(in))
|
|
re.off += 8
|
|
}
|
|
|
|
func (re *realEncoder) putArrayLength(in int) error {
|
|
re.putInt32(int32(in))
|
|
return nil
|
|
}
|
|
|
|
// collection
|
|
|
|
func (re *realEncoder) putRawBytes(in []byte) error {
|
|
copy(re.raw[re.off:], in)
|
|
re.off += len(in)
|
|
return nil
|
|
}
|
|
|
|
func (re *realEncoder) putBytes(in []byte) error {
|
|
if in == nil {
|
|
re.putInt32(-1)
|
|
return nil
|
|
}
|
|
re.putInt32(int32(len(in)))
|
|
copy(re.raw[re.off:], in)
|
|
re.off += len(in)
|
|
return nil
|
|
}
|
|
|
|
func (re *realEncoder) putString(in string) error {
|
|
re.putInt16(int16(len(in)))
|
|
copy(re.raw[re.off:], in)
|
|
re.off += len(in)
|
|
return nil
|
|
}
|
|
|
|
func (re *realEncoder) putStringArray(in []string) error {
|
|
err := re.putArrayLength(len(in))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, val := range in {
|
|
if err := re.putString(val); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (re *realEncoder) putInt32Array(in []int32) error {
|
|
err := re.putArrayLength(len(in))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, val := range in {
|
|
re.putInt32(val)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (re *realEncoder) putInt64Array(in []int64) error {
|
|
err := re.putArrayLength(len(in))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, val := range in {
|
|
re.putInt64(val)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (re *realEncoder) offset() int {
|
|
return re.off
|
|
}
|
|
|
|
// stacks
|
|
|
|
func (re *realEncoder) push(in pushEncoder) {
|
|
in.saveOffset(re.off)
|
|
re.off += in.reserveLength()
|
|
re.stack = append(re.stack, in)
|
|
}
|
|
|
|
func (re *realEncoder) pop() error {
|
|
// this is go's ugly pop pattern (the inverse of append)
|
|
in := re.stack[len(re.stack)-1]
|
|
re.stack = re.stack[:len(re.stack)-1]
|
|
|
|
return in.run(re.off, re.raw)
|
|
}
|
|
|
|
// we do record metrics during the real encoder pass
|
|
func (re *realEncoder) metricRegistry() metrics.Registry {
|
|
return re.registry
|
|
}
|