// decodeCompoundMessage splits a compound message and returns
// the slices of individual messages. Also returns the number
// of truncated messages and any potential error
760313
func decodeCompoundMessage(buf []byte) (trunc int, parts [][]byte, err error) {
	if len(buf) < 1 {
		err = fmt.Errorf("missing compound length byte")
		return
	}
	numParts := uint8(buf[0])
	buf = buf[1:]

	// Check we have enough bytes
	if len(buf) < int(numParts*2) {
		err = fmt.Errorf("truncated len slice")
		return
	}

	// Decode the lengths
	lengths := make([]uint16, numParts)
	for i := 0; i < int(numParts); i++ {
		lengths[i] = binary.BigEndian.Uint16(buf[i*2 : i*2+2])
	}
	buf = buf[numParts*2:]

	// Split each message
	for idx, msgLen := range lengths {
		if len(buf) < int(msgLen) {
			trunc = int(numParts) - idx
			return
		}

		// Extract the slice, seek past on the buffer
		slice := buf[:msgLen]
		buf = buf[msgLen:]
		parts = append(parts, slice)
	}
	return
}
138609
func (dec *Decoder) Decode() (m *Message, err error) {

	dec.mu.Lock()
	dec.line, err = dec.reader.ReadString(delim)
	dec.mu.Unlock()

	if err != nil {
		return nil, err
	}

	return ParseMessage(dec.line), nil
}
788670
func (m *MesosMessenger) decodeLoop() {
	for {
		select {
		case <-m.stop:
			return
		default:
		}
		msg, err := m.tr.Recv()
		if err != nil {
			if err == discardOnStopError {
				log.V(1).Info("exiting decodeLoop, transport shutting down")
				return
			} else {
				panic(fmt.Sprintf("unexpected transport error: %v", err))
			}
		}

		log.V(2).Infof("Receiving message %v from %v\n", msg.Name, msg.UPID)
		protoMessage, handler, found := m.messageBinding(msg.Name)
		if !found {
			log.Warningf("no message binding for message %q", msg.Name)
			continue
		}

		msg.ProtoMessage = protoMessage
		if err := proto.Unmarshal(msg.Bytes, msg.ProtoMessage); err != nil {
			log.Errorf("Failed to unmarshal message %v: %v\n", msg, err)
			continue
		}

		handler(msg.UPID, msg.ProtoMessage)
	}
}
1003782
func (z *Archive) DecodeMsg(dc *msgp.Reader) (err error) {
	var field []byte
	_ = field
	var zb0001 uint32
	zb0001, err = dc.ReadMapHeader()
	if err != nil {
		err = msgp.WrapError(err)
		return
	}
	for zb0001 > 0 {
		zb0001--
		field, err = dc.ReadMapKeyPtr()
		if err != nil {
			err = msgp.WrapError(err)
			return
		}
		switch msgp.UnsafeString(field) {
		case "MetricDefinition":
			err = z.MetricDefinition.DecodeMsg(dc)
			if err != nil {
				err = msgp.WrapError(err, "MetricDefinition")
				return
			}
		case "SchemaId":
			z.SchemaId, err = dc.ReadUint16()
			if err != nil {
				err = msgp.WrapError(err, "SchemaId")
				return
			}
		case "AggId":
			z.AggId, err = dc.ReadUint16()
			if err != nil {
				err = msgp.WrapError(err, "AggId")
				return
			}
		case "IrId":
			z.IrId, err = dc.ReadUint16()
			if err != nil {
				err = msgp.WrapError(err, "IrId")
				return
			}
		case "LastSave":
			z.LastSave, err = dc.ReadUint32()
			if err != nil {
				err = msgp.WrapError(err, "LastSave")
				return
			}
		default:
			err = dc.Skip()
			if err != nil {
				err = msgp.WrapError(err)
				return
			}
		}
	}
	return
}
1237442
func Decode(text string) (tag, message string, ok bool) {

	// Fast path, return if this text does not contain a CTCP message.
	if len(text) < 3 || text[0] != delimiter || text[len(text)-1] != delimiter {
		return empty, empty, false
	}

	s := strings.IndexByte(text, space)

	if s < 0 {

		// Messages may contain only a tag.
		return text[1 : len(text)-1], empty, true
	}

	return text[1:s], text[s+1 : len(text)-1], true
}
881316
func (z *runIterator16) DecodeMsg(dc *msgp.Reader) (err error) {
	var field []byte
	_ = field
	var zqke uint32
	zqke, err = dc.ReadMapHeader()
	if err != nil {
		return
	}
	for zqke > 0 {
		zqke--
		field, err = dc.ReadMapKeyPtr()
		if err != nil {
			return
		}
		switch msgp.UnsafeString(field) {
		case "rc":
			if dc.IsNil() {
				err = dc.ReadNil()
				if err != nil {
					return
				}
				z.rc = nil
			} else {
				if z.rc == nil {
					z.rc = new(runContainer16)
				}
				err = z.rc.DecodeMsg(dc)
				if err != nil {
					return
				}
			}
		case "curIndex":
			z.curIndex, err = dc.ReadInt64()
			if err != nil {
				return
			}
		case "curPosInIndex":
			z.curPosInIndex, err = dc.ReadUint16()
			if err != nil {
				return
			}
		case "curSeq":
			z.curSeq, err = dc.ReadInt64()
			if err != nil {
				return
			}
		default:
			err = dc.Skip()
			if err != nil {
				return
			}
		}
	}
	return
}
942652
func (z *uint16Slice) DecodeMsg(dc *msgp.Reader) (err error) {
	var zjpj uint32
	zjpj, err = dc.ReadArrayHeader()
	if err != nil {
		return
	}
	if cap((*z)) >= int(zjpj) {
		(*z) = (*z)[:zjpj]
	} else {
		(*z) = make(uint16Slice, zjpj)
	}
	for zywj := range *z {
		(*z)[zywj], err = dc.ReadUint16()
		if err != nil {
			return
		}
	}
	return
}
115920
func Decode(buf []byte, out interface{}) error {
	return codec.NewDecoder(bytes.NewReader(buf), MsgpackHandle).Decode(out)
}
51773
func DecodeMsgMempool(msg *pstypes.WebSocketMessage) (*exptypes.MempoolShort, error) {
	mps, err := DecodeMsg(msg)
	if err != nil {
		return nil, err
	}
	mpShort, ok := mps.(*exptypes.MempoolShort)
	if !ok {
		return nil, fmt.Errorf("content of Message was not of type *exptypes.MempoolShort")
	}
	return mpShort, nil
}
988594
func convertMessage(data interface{}) (string, error) {
	switch data.(type) {
	case string:
		return data.(string), nil
	}

	// An unexpected type. We'll get the type name for the error, but this
	// will fail the export.. so it only uses reflect once.
	name := reflect.TypeOf(data)
	return "", &UnknownElasticStructError{fmt.Sprintf("%v", name), "message"}
}
4261
func (s *AuthService) decodeMessage(m *pubSubMessage, certs *signing.PublicCertificates) (*protocol.ChangeNotification, error) {
	// Key name used to sign.
	keyName := m.Message.Attributes["X-AuthDB-SigKey-v1"]
	if keyName == "" {
		return nil, fmt.Errorf("X-AuthDB-SigKey-v1 attribute is not set")
	}

	// The signature.
	sigBase64 := m.Message.Attributes["X-AuthDB-SigVal-v1"]
	if sigBase64 == "" {
		return nil, fmt.Errorf("X-AuthDB-SigVal-v1 attribute is not set")
	}
	sig, err := base64.StdEncoding.DecodeString(sigBase64)
	if err != nil {
		return nil, fmt.Errorf("the message signature is not valid base64 - %s", err)
	}

	// Message body.
	body, err := base64.StdEncoding.DecodeString(m.Message.Data)
	if err != nil {
		return nil, fmt.Errorf("the message body is not valid base64 - %s", err)
	}

	// Validate.
	if err := certs.CheckSignature(keyName, body, sig); err != nil {
		return nil, err
	}

	// Deserialize.
	out := protocol.ChangeNotification{}
	if err := proto.Unmarshal(body, &out); err != nil {
		return nil, err
	}
	return &out, nil
}
267308
func Decode(data []byte) (*Message, error) {
	if len(data) < msgHeadLength {
		return nil, ErrInvalidMessage
	}
	m := New()
	flag := data[0]
	offset := 1
	m.Type = Type((flag >> 1) & msgTypeMask)

	if invalidType(m.Type) {
		return nil, ErrWrongMessageType
	}

	if m.Type == Request || m.Type == Response {
		id := uint(0)
		// little end byte order
		// WARNING: must can be stored in 64 bits integer
		// variant length encode
		for i := offset; i < len(data); i++ {
			b := data[i]
			id += uint(b&0x7F) << uint(7*(i-offset))
			if b < 128 {
				offset = i + 1
				break
			}
		}
		m.ID = id
	}

	m.Err = flag&errorMask == errorMask

	if routable(m.Type) {
		if flag&msgRouteCompressMask == 1 {
			m.compressed = true
			code := binary.BigEndian.Uint16(data[offset:(offset + 2)])
			route, ok := codes[code]
			if !ok {
				return nil, ErrRouteInfoNotFound
			}
			m.Route = route
			offset += 2
		} else {
			m.compressed = false
			rl := data[offset]
			offset++
			m.Route = string(data[offset:(offset + int(rl))])
			offset += int(rl)
		}
	}

	m.Data = data[offset:]
	var err error
	if flag&gzipMask == gzipMask {
		m.Data, err = compression.InflateData(m.Data)
		if err != nil {
			return nil, err
		}
	}
	return m, nil
}
379552
func (z *Message) DecodeMsg(dc *msgp.Reader) (err error) {
	var zb0001 uint32
	zb0001, err = dc.ReadArrayHeader()
	if err != nil {
		err = msgp.WrapError(err)
		return
	}
	if zb0001 != 4 {
		err = msgp.ArrayError{Wanted: 4, Got: zb0001}
		return
	}
	z.Tag, err = dc.ReadString()
	if err != nil {
		err = msgp.WrapError(err, "Tag")
		return
	}
	z.Time, err = dc.ReadInt64()
	if err != nil {
		err = msgp.WrapError(err, "Time")
		return
	}
	z.Record, err = dc.ReadIntf()
	if err != nil {
		err = msgp.WrapError(err, "Record")
		return
	}
	var zb0002 uint32
	zb0002, err = dc.ReadMapHeader()
	if err != nil {
		err = msgp.WrapError(err, "Option")
		return
	}
	if z.Option == nil {
		z.Option = make(map[string]string, zb0002)
	} else if len(z.Option) > 0 {
		for key := range z.Option {
			delete(z.Option, key)
		}
	}
	for zb0002 > 0 {
		zb0002--
		var za0001 string
		var za0002 string
		za0001, err = dc.ReadString()
		if err != nil {
			err = msgp.WrapError(err, "Option")
			return
		}
		za0002, err = dc.ReadString()
		if err != nil {
			err = msgp.WrapError(err, "Option", za0001)
			return
		}
		z.Option[za0001] = za0002
	}
	return
}
132812
func CombineMessage(resp *aurora.Response) string {
	var buffer bytes.Buffer
	for _, detail := range resp.GetDetails() {
		buffer.WriteString(detail.GetMessage() + ", ")
	}

	if buffer.Len() > 0 {
		buffer.Truncate(buffer.Len() - 2) // Get rid of trailing comma + space
	}
	return buffer.String()
}
1028942
func (*MsgCodec) DecodeMsg(data []byte, msg api.Message) error {
	if msg == nil {
		return errors.New("nil message passed in")
	}

	var header interface{}

	// check which header is expected
	switch msg.GetMessageType() {
	case api.RequestMessage:
		header = new(VppRequestHeader)
	case api.ReplyMessage:
		header = new(VppReplyHeader)
	case api.EventMessage:
		header = new(VppEventHeader)
	default:
		header = new(VppOtherHeader)
	}

	buf := bytes.NewReader(data)

	// decode message header
	if err := struc.Unpack(buf, header); err != nil {
		return fmt.Errorf("failed to decode message header: %+v, error: %v", header, err)
	}

	// decode message content
	if err := struc.Unpack(buf, msg); err != nil {
		return fmt.Errorf("failed to decode message data: %+v, error: %v", data, err)
	}

	return nil
}
806398
func ParseMessage(data []byte) (Message, error) {
	rv := Message{}
	return rv, rv.UnmarshalBinary(data)
}
13167
func (self *Client) CaptureMessage(message string, extra map[string]interface{}) (err error) {
	timestamp := time.Now().UTC()
	timestampStr := timestamp.Format(iso8601)

	packet := sentryRequest{
		Project:   self.Project,
		Message:   message,
		Timestamp: timestampStr,
		Level:     "error",
		Logger:    self.Logger,
		Extra:     extra,
	}

	buf := new(bytes.Buffer)
	b64Encoder := base64.NewEncoder(base64.StdEncoding, buf)
	writer := zlib.NewWriter(b64Encoder)
	jsonEncoder := json.NewEncoder(writer)

	if err := jsonEncoder.Encode(packet); err != nil {
		return err
	}

	err = writer.Close()
	if err != nil {
		return err
	}

	err = b64Encoder.Close()
	if err != nil {
		return err
	}

	_, err = self.sentryTransport.Send(buf.Bytes(), timestamp)
	if err != nil {
		return err
	}

	return nil
}