featurebase/internal/internal.go
Ben Johnson a632d08629 refactor
This commit refactors the pilosa codebase. It makes several major
changes:

* Removes bitmap handles
* Removes dispatch/hold/transport
* Removes etcd dependency
* Adds consistent hash ring for slice placement
* Refactors parser/lexer
* Adds strong typing to PQL AST
* Flattens package hierarchy
2015-12-02 15:34:49 -07:00

56 lines
1,008 B
Go

package internal
import (
"io"
"io/ioutil"
"github.com/gogo/protobuf/proto"
)
type Request proto.Message
type Response proto.Message
// Encoder encodes messages to a writer.
type Encoder struct {
w io.Writer
}
// NewEncoder returns a new instance of Encoder.
func NewEncoder(w io.Writer) *Encoder {
return &Encoder{w: w}
}
// Encode marshals m into bytes and writes them to r.
func (enc *Encoder) Encode(pb proto.Message) error {
buf, err := proto.Marshal(pb)
if err != nil {
return err
}
if _, err := enc.w.Write(buf); err != nil {
return err
}
return nil
}
// Decoder decodes messages from a reader.
type Decoder struct {
r io.Reader
}
// NewDecoder returns a new instance of Decoder.
func NewDecoder(r io.Reader) *Decoder {
return &Decoder{r: r}
}
// Decode reads all bytes from the reader and unmarshals them into pb.
func (dec *Decoder) Decode(pb proto.Message) error {
buf, err := ioutil.ReadAll(dec.r)
if err != nil {
return err
}
return proto.Unmarshal(buf, pb)
}