Skip to content

Commit

Permalink
Unexport MsgType
Browse files Browse the repository at this point in the history
  • Loading branch information
tylertreat committed Feb 27, 2020
1 parent 1fe465f commit a45e004
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions server/proto/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
client "github.com/liftbridge-io/liftbridge-api/go"
)

// MsgType indicates the type of message contained by an envelope.
type MsgType byte
// msgType indicates the type of message contained by an envelope.
type msgType byte

const (
msgTypePublish MsgType = iota
msgTypePublish msgType = iota
msgTypeAck

msgTypeReplicationRequest
Expand Down Expand Up @@ -159,7 +159,7 @@ func WriteReplicationResponseHeader(buf *bytes.Buffer) int {

// marshalEnvelope serializes a protobuf message into the Liftbridge envelope
// wire format.
func marshalEnvelope(msg pb.Message, msgType MsgType) ([]byte, error) {
func marshalEnvelope(msg pb.Message, msgType msgType) ([]byte, error) {
data, err := pb.Marshal(msg)
if err != nil {
return nil, err
Expand Down Expand Up @@ -350,15 +350,15 @@ func UnmarshalReplicationResponse(data []byte) (uint64, int64, []byte, error) {

// unmarshalEnvelope deserializes a Liftbridge envelope into a protobuf
// message.
func unmarshalEnvelope(data []byte, msg pb.Message, msgType MsgType) error {
func unmarshalEnvelope(data []byte, msg pb.Message, msgType msgType) error {
payload, err := checkEnvelope(data, msgType)
if err != nil {
return err
}
return pb.Unmarshal(payload, msg)
}

func checkEnvelope(data []byte, msgType MsgType) ([]byte, error) {
func checkEnvelope(data []byte, expectedType msgType) ([]byte, error) {
if len(data) < envelopeMinHeaderLen {
return nil, errors.New("data missing envelope header")
}
Expand All @@ -372,12 +372,12 @@ func checkEnvelope(data []byte, msgType MsgType) ([]byte, error) {
var (
headerLen = int(data[5])
flags = data[6]
actualType = MsgType(data[7])
actualType = msgType(data[7])
payload = data[headerLen:]
)

if actualType != msgType {
return nil, fmt.Errorf("MsgType mismatch: expected %v, got %v", msgType, actualType)
if actualType != expectedType {
return nil, fmt.Errorf("MsgType mismatch: expected %v, got %v", expectedType, actualType)
}

// Check CRC.
Expand Down

0 comments on commit a45e004

Please sign in to comment.