Exemplo n.º 1
0
// return a fixed-size expression, if possible.
// only possible for *BaseElem and *Array.
// returns (expr, ok)
func fixedsizeExpr(e Elem) (string, bool) {
	switch e := e.(type) {
	case *Array:
		if str, ok := fixedsizeExpr(e.Els); ok {
			return fmt.Sprintf("(%s * (%s))", e.Size, str), true
		}
	case *BaseElem:
		if fixedSize(e.Value) {
			return builtinSize(e.BaseName()), true
		}
	case *Struct:
		var str string
		for _, f := range e.Fields {
			if fs, ok := fixedsizeExpr(f.FieldElem); ok {
				if str == "" {
					str = fs
				} else {
					str += "+" + fs
				}
			} else {
				return "", false
			}
		}
		var hdrlen int
		mhdr := msgp.AppendMapHeader(nil, uint32(len(e.Fields)))
		hdrlen += len(mhdr)
		var strbody []byte
		for _, f := range e.Fields {
			strbody = msgp.AppendString(strbody[:0], f.FieldTag)
			hdrlen += len(strbody)
		}
		return fmt.Sprintf("%d + %s", hdrlen, str), true
	}
	return "", false
}
Exemplo n.º 2
0
// MarshalMsg implements msgp.Marshaler
func (z *ProbeEvent) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	// map header, size 8
	// string "Id"
	o = append(o, 0x88, 0xa2, 0x49, 0x64)
	o = msgp.AppendString(o, z.Id)
	// string "EventType"
	o = append(o, 0xa9, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65)
	o = msgp.AppendString(o, z.EventType)
	// string "OrgId"
	o = append(o, 0xa5, 0x4f, 0x72, 0x67, 0x49, 0x64)
	o = msgp.AppendInt64(o, z.OrgId)
	// string "Severity"
	o = append(o, 0xa8, 0x53, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79)
	o = msgp.AppendString(o, z.Severity)
	// string "Source"
	o = append(o, 0xa6, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65)
	o = msgp.AppendString(o, z.Source)
	// string "Timestamp"
	o = append(o, 0xa9, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70)
	o = msgp.AppendInt64(o, z.Timestamp)
	// string "Message"
	o = append(o, 0xa7, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65)
	o = msgp.AppendString(o, z.Message)
	// string "Tags"
	o = append(o, 0xa4, 0x54, 0x61, 0x67, 0x73)
	o = msgp.AppendMapHeader(o, uint32(len(z.Tags)))
	for xvk, bzg := range z.Tags {
		o = msgp.AppendString(o, xvk)
		o = msgp.AppendString(o, bzg)
	}
	return
}
Exemplo n.º 3
0
func (s *sizeGen) gStruct(st *Struct) {
	if !s.p.ok() {
		return
	}

	nfields := uint32(len(st.Fields))

	if st.AsTuple {
		data := msgp.AppendArrayHeader(nil, nfields)
		s.addConstant(strconv.Itoa(len(data)))
		for i := range st.Fields {
			if !s.p.ok() {
				return
			}
			next(s, st.Fields[i].FieldElem)
		}
	} else {
		data := msgp.AppendMapHeader(nil, nfields)
		s.addConstant(strconv.Itoa(len(data)))
		for i := range st.Fields {
			data = data[:0]
			data = msgp.AppendString(data, st.Fields[i].FieldTag)
			s.addConstant(strconv.Itoa(len(data)))
			next(s, st.Fields[i].FieldElem)
		}
	}
}
Exemplo n.º 4
0
// MarshalMsg implements msgp.Marshaler
func (z *FieldT) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	// map header, size 7
	// string "FieldId"
	o = append(o, 0x87, 0xa7, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x49, 0x64)
	o = msgp.AppendInt64(o, z.FieldId)
	// string "Name"
	o = append(o, 0xa4, 0x4e, 0x61, 0x6d, 0x65)
	o = msgp.AppendString(o, z.Name)
	// string "Ztyp"
	o = append(o, 0xa4, 0x5a, 0x74, 0x79, 0x70)
	o = msgp.AppendInt32(o, int32(z.Ztyp))
	// string "IsVarArg"
	o = append(o, 0xa8, 0x49, 0x73, 0x56, 0x61, 0x72, 0x41, 0x72, 0x67)
	o = msgp.AppendBool(o, z.IsVarArg)
	// string "Tags"
	o = append(o, 0xa4, 0x54, 0x61, 0x67, 0x73)
	o = msgp.AppendMapHeader(o, uint32(len(z.Tags)))
	for zxvk, zbzg := range z.Tags {
		o = msgp.AppendString(o, zxvk)
		o = msgp.AppendString(o, zbzg)
	}
	// string "Deprecated"
	o = append(o, 0xaa, 0x44, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64)
	o = msgp.AppendBool(o, z.Deprecated)
	// string "Comment"
	o = append(o, 0xa7, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74)
	o = msgp.AppendString(o, z.Comment)
	return
}
Exemplo n.º 5
0
// MarshalMsg implements msgp.Marshaler
func (z *Incident) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	o = msgp.AppendMapHeader(o, 9)
	o = msgp.AppendString(o, "event_name")
	o = msgp.AppendBytes(o, z.EventName)
	o = msgp.AppendString(o, "time")
	o = msgp.AppendInt64(o, z.Time)
	o = msgp.AppendString(o, "id")
	o = msgp.AppendInt64(o, z.Id)
	o = msgp.AppendString(o, "active")
	o = msgp.AppendBool(o, z.Active)
	o = msgp.AppendString(o, "escalation")
	o = msgp.AppendString(o, z.Escalation)
	o = msgp.AppendString(o, "description")
	o = msgp.AppendString(o, z.Description)
	o = msgp.AppendString(o, "policy")
	o = msgp.AppendString(o, z.Policy)
	o = msgp.AppendString(o, "Status")
	o = msgp.AppendInt(o, z.Status)
	o = msgp.AppendString(o, "Event")
	o, err = z.Event.MarshalMsg(o)
	if err != nil {
		return
	}
	return
}
Exemplo n.º 6
0
// MarshalMsg implements msgp.Marshaler
func (z *Event) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	o = msgp.AppendMapHeader(o, 5)
	o = msgp.AppendString(o, "host")
	o = msgp.AppendString(o, z.Host)
	o = msgp.AppendString(o, "service")
	o = msgp.AppendString(o, z.Service)
	o = msgp.AppendString(o, "sub_service")
	o = msgp.AppendString(o, z.SubService)
	o = msgp.AppendString(o, "metric")
	o = msgp.AppendFloat64(o, z.Metric)
	o = msgp.AppendString(o, "tags")
	o = msgp.AppendMapHeader(o, uint32(len(z.Tags)))
	for xvk, bzg := range z.Tags {
		o = msgp.AppendString(o, xvk)
		o = msgp.AppendString(o, bzg)
	}
	return
}
Exemplo n.º 7
0
func (e *encodeGen) structmap(s *Struct) {
	nfields := len(s.Fields)
	data := msgp.AppendMapHeader(nil, uint32(nfields))
	e.p.printf("\n// map header, size %d", nfields)
	e.Fuse(data)
	for i := range s.Fields {
		if !e.p.ok() {
			return
		}
		data = msgp.AppendString(nil, s.Fields[i].FieldTag)
		e.p.printf("\n// write %q", s.Fields[i].FieldTag)
		e.Fuse(data)
		next(e, s.Fields[i].FieldElem)
	}
}
Exemplo n.º 8
0
func (m *marshalGen) mapstruct(s *Struct) {
	data := make([]byte, 0, 64)
	data = msgp.AppendMapHeader(data, uint32(len(s.Fields)))
	m.p.printf("\n// map header, size %d", len(s.Fields))
	m.Fuse(data)
	for i := range s.Fields {
		if !m.p.ok() {
			return
		}
		data = msgp.AppendString(nil, s.Fields[i].FieldTag)

		m.p.printf("\n// string %q", s.Fields[i].FieldTag)
		m.Fuse(data)

		next(m, s.Fields[i].FieldElem)
	}
}
Exemplo n.º 9
0
// MarshalMsg implements msgp.Marshaler
func (z *MetricDefinition) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	// map header, size 11
	// string "Id"
	o = append(o, 0x8b, 0xa2, 0x49, 0x64)
	o = msgp.AppendString(o, z.Id)
	// string "OrgId"
	o = append(o, 0xa5, 0x4f, 0x72, 0x67, 0x49, 0x64)
	o = msgp.AppendInt(o, z.OrgId)
	// string "Name"
	o = append(o, 0xa4, 0x4e, 0x61, 0x6d, 0x65)
	o = msgp.AppendString(o, z.Name)
	// string "Metric"
	o = append(o, 0xa6, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63)
	o = msgp.AppendString(o, z.Metric)
	// string "Interval"
	o = append(o, 0xa8, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c)
	o = msgp.AppendInt(o, z.Interval)
	// string "Unit"
	o = append(o, 0xa4, 0x55, 0x6e, 0x69, 0x74)
	o = msgp.AppendString(o, z.Unit)
	// string "TargetType"
	o = append(o, 0xaa, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x54, 0x79, 0x70, 0x65)
	o = msgp.AppendString(o, z.TargetType)
	// string "Tags"
	o = append(o, 0xa4, 0x54, 0x61, 0x67, 0x73)
	o = msgp.AppendArrayHeader(o, uint32(len(z.Tags)))
	for hct := range z.Tags {
		o = msgp.AppendString(o, z.Tags[hct])
	}
	// string "LastUpdate"
	o = append(o, 0xaa, 0x4c, 0x61, 0x73, 0x74, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65)
	o = msgp.AppendInt64(o, z.LastUpdate)
	// string "Nodes"
	o = append(o, 0xa5, 0x4e, 0x6f, 0x64, 0x65, 0x73)
	o = msgp.AppendMapHeader(o, uint32(len(z.Nodes)))
	for cua, xhx := range z.Nodes {
		o = msgp.AppendString(o, cua)
		o = msgp.AppendString(o, xhx)
	}
	// string "NodeCount"
	o = append(o, 0xa9, 0x4e, 0x6f, 0x64, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74)
	o = msgp.AppendInt(o, z.NodeCount)
	return
}
Exemplo n.º 10
0
// MarshalMsg implements msgp.Marshaler
func (z *Message) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	// map header, size 3
	// string "body"
	o = append(o, 0x83, 0xa4, 0x62, 0x6f, 0x64, 0x79)
	o = msgp.AppendBytes(o, z.Body)
	// string "meta"
	o = append(o, 0xa4, 0x6d, 0x65, 0x74, 0x61)
	o = msgp.AppendMapHeader(o, uint32(len(z.Meta)))
	for xvk, bzg := range z.Meta {
		o = msgp.AppendString(o, xvk)
		o, err = msgp.AppendIntf(o, bzg)
		if err != nil {
			return
		}
	}
	// string "ct"
	o = append(o, 0xa2, 0x63, 0x74)
	o = msgp.AppendString(o, z.ContentType)
	return
}
Exemplo n.º 11
0
// MarshalMsg implements msgp.Marshaler
func (z *Car) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	// map header, size 5
	// string "CarId"
	o = append(o, 0x85, 0xa5, 0x43, 0x61, 0x72, 0x49, 0x64)
	o = msgp.AppendInt(o, z.CarId)
	// string "CarName"
	o = append(o, 0xa7, 0x43, 0x61, 0x72, 0x4e, 0x61, 0x6d, 0x65)
	o = msgp.AppendString(o, z.CarName)
	// string "Attributes"
	o = append(o, 0xaa, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73)
	o = msgp.AppendArrayHeader(o, uint32(len(z.Attributes)))
	for bai := range z.Attributes {
		// map header, size 3
		// string "Id"
		o = append(o, 0x83, 0xa2, 0x49, 0x64)
		o = msgp.AppendInt(o, z.Attributes[bai].Id)
		// string "Name"
		o = append(o, 0xa4, 0x4e, 0x61, 0x6d, 0x65)
		o = msgp.AppendString(o, z.Attributes[bai].Name)
		// string "Value"
		o = append(o, 0xa5, 0x56, 0x61, 0x6c, 0x75, 0x65)
		o = msgp.AppendString(o, z.Attributes[bai].Value)
	}
	// string "FlagMap"
	o = append(o, 0xa7, 0x46, 0x6c, 0x61, 0x67, 0x4d, 0x61, 0x70)
	o = msgp.AppendMapHeader(o, uint32(len(z.FlagMap)))
	for cmr, ajw := range z.FlagMap {
		o = msgp.AppendString(o, cmr)
		o = msgp.AppendString(o, ajw)
	}
	// string "Ttl"
	o = append(o, 0xa3, 0x54, 0x74, 0x6c)
	o = msgp.AppendInt(o, z.Ttl)
	return
}