Ejemplo n.º 1
0
// UnmarshalMsg implements msgp.Unmarshaler
func (z *Subload) UnmarshalMsg(bts []byte) (o []byte, err error) {
	var field []byte
	_ = field
	var isz uint32
	isz, bts, err = msgp.ReadMapHeaderBytes(bts)
	if err != nil {
		return
	}
	for isz > 0 {
		isz--
		field, bts, err = msgp.ReadMapKeyZC(bts)
		if err != nil {
			return
		}
		switch msgp.UnsafeString(field) {
		case "A":
			z.A, bts, err = msgp.ReadStringBytes(bts)
			if err != nil {
				return
			}
		case "B":
			z.B, bts, err = msgp.ReadIntBytes(bts)
			if err != nil {
				return
			}
		case "F":
			var xsz uint32
			xsz, bts, err = msgp.ReadArrayHeaderBytes(bts)
			if err != nil {
				return
			}
			if cap(z.F) >= int(xsz) {
				z.F = z.F[:xsz]
			} else {
				z.F = make([]float64, xsz)
			}
			for cmr := range z.F {
				z.F[cmr], bts, err = msgp.ReadFloat64Bytes(bts)
				if err != nil {
					return
				}
			}
		default:
			bts, err = msgp.Skip(bts)
			if err != nil {
				return
			}
		}
	}
	o = bts
	return
}
Ejemplo n.º 2
0
func TestMarshalUnmarshalPayload(t *testing.T) {
	v := Payload{}
	bts, err := v.MarshalMsg(nil)
	if err != nil {
		t.Fatal(err)
	}
	left, err := v.UnmarshalMsg(bts)
	if err != nil {
		t.Fatal(err)
	}
	if len(left) > 0 {
		t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left)
	}

	left, err = msgp.Skip(bts)
	if err != nil {
		t.Fatal(err)
	}
	if len(left) > 0 {
		t.Errorf("%d bytes left over after Skip(): %q", len(left), left)
	}
}
Ejemplo n.º 3
0
// UnmarshalMsg implements msgp.Unmarshaler
func (z *Payload) UnmarshalMsg(bts []byte) (o []byte, err error) {
	var field []byte
	_ = field
	var isz uint32
	isz, bts, err = msgp.ReadMapHeaderBytes(bts)
	if err != nil {
		return
	}
	for isz > 0 {
		isz--
		field, bts, err = msgp.ReadMapKeyZC(bts)
		if err != nil {
			return
		}
		switch msgp.UnsafeString(field) {
		case "Sub":
			bts, err = z.Sub.UnmarshalMsg(bts)
			if err != nil {
				return
			}
		case "D":
			var xsz uint32
			xsz, bts, err = msgp.ReadArrayHeaderBytes(bts)
			if err != nil {
				return
			}
			if cap(z.D) >= int(xsz) {
				z.D = z.D[:xsz]
			} else {
				z.D = make([]string, xsz)
			}
			for xvk := range z.D {
				z.D[xvk], bts, err = msgp.ReadStringBytes(bts)
				if err != nil {
					return
				}
			}
		case "E":
			var xsz uint32
			xsz, bts, err = msgp.ReadArrayHeaderBytes(bts)
			if err != nil {
				return
			}
			if cap(z.E) >= int(xsz) {
				z.E = z.E[:xsz]
			} else {
				z.E = make([]int32, xsz)
			}
			for bzg := range z.E {
				z.E[bzg], bts, err = msgp.ReadInt32Bytes(bts)
				if err != nil {
					return
				}
			}
		case "G":
			var xsz uint32
			xsz, bts, err = msgp.ReadArrayHeaderBytes(bts)
			if err != nil {
				return
			}
			if cap(z.G) >= int(xsz) {
				z.G = z.G[:xsz]
			} else {
				z.G = make([]float64, xsz)
			}
			for bai := range z.G {
				z.G[bai], bts, err = msgp.ReadFloat64Bytes(bts)
				if err != nil {
					return
				}
			}
		case "Blob":
			z.Blob, bts, err = msgp.ReadBytesBytes(bts, z.Blob)
			if err != nil {
				return
			}
		default:
			bts, err = msgp.Skip(bts)
			if err != nil {
				return
			}
		}
	}
	o = bts
	return
}