Exemple #1
0
func (c *Core) MarshalJSON() ([]byte, os.Error) {
	var w bytes.Buffer
	fmt.Fprintf(&w, "{\"Build\":%s,\"Id\":%s,\"Lifetime\":%d,",
		misc.JSONQuote(c.GetBuild()), c.GetMyId().ToJSON(), time.Nanoseconds()-c.since)
	nj, err := c.FriendsMarshalJSON()
	if err != nil {
		return nil, err
	}
	dj, err := c.dialer.MarshalJSON()
	if err != nil {
		return nil, err
	}
	cj, err := c.compass.MarshalJSON()
	if err != nil {
		return nil, err
	}
	vj, err := c.vault.MarshalJSON()
	if err != nil {
		return nil, err
	}
	fj, err := c.fe.MarshalJSON()
	if err != nil {
		return nil, err
	}
	fmt.Fprintf(&w, "\"Friends\":%s,\"Dialer\":%s,\"Compass\":%s,\"Vault\":%s,\"FrontEnd\":%s}",
		nj, dj, cj, vj, fj)
	return w.Bytes(), nil
}
Exemple #2
0
func (fe *FrontEnd) MarshalJSON() ([]byte, os.Error) {
	fe.lk.Lock()
	defer fe.lk.Unlock()
	var w bytes.Buffer
	fmt.Fprintf(&w, "{\"UserAgent\":%s,\"ServerFD\":%d,"+
		"\"ServerFDLim\":%d,\"WWWClientFD\":%d,\"WWWClientFDLim\":%d}",
		misc.JSONQuote(fe.useragent),
		fe.server.GetFDLimiter().LockCount(), fe.server.GetFDLimiter().Limit(),
		fe.wwwclient.GetFDLimiter().LockCount(), fe.wwwclient.GetFDLimiter().Limit())
	return w.Bytes(), nil
}
Exemple #3
0
func (y *Conn) MarshalJSON() ([]byte, os.Error) {
	y.lk.Lock()
	defer y.lk.Unlock()

	var w bytes.Buffer
	if y.id != nil {
		if y.h != nil {
			fmt.Fprintf(&w, "{\"CTag\":%d,\"HTag\":%d,\"Session\":\"%x\","+
				"\"Id\":%s,\"Err\":%s,\"Regime\":%s}",
				y.tag, y.h.GetTag(), y.h.GetSession(),
				y.id.ToJSON(),
				misc.JSONQuote(errorToString(y.err)),
				misc.JSONQuote(regimeToString(y.regime)))
		} else {
			fmt.Fprintf(&w, "{\"CTag\":%d,\"Id\":%s,\"Err\":%s,\"Regime\":%s}",
				y.tag,
				y.id.ToJSON(),
				misc.JSONQuote(errorToString(y.err)),
				misc.JSONQuote(regimeToString(y.regime)))
		}
	} else {
		fmt.Fprintf(&w, "{\"CTag\":%d,\"Err\":%s,\"Regime\":%s}",
			y.tag,
			misc.JSONQuote(errorToString(y.err)),
			misc.JSONQuote(regimeToString(y.regime)))
	}
	return w.Bytes(), nil
}
Exemple #4
0
func (d *Dialer0) MarshalJSON() ([]byte, os.Error) {
	d.lk.Lock()
	defer d.lk.Unlock()
	var w bytes.Buffer
	fmt.Fprintf(&w, "{\"FD\":%d,\"FDLim\":%d,\"Services\":[",
		d.fdlim.LockCount(), d.fdlim.Limit())
	comma := false
	for subj, _ := range d.listens {
		if comma {
			fmt.Fprintf(&w, ",")
		}
		fmt.Fprintf(&w, "%s", misc.JSONQuote(subj))
		comma = true
	}
	fmt.Fprintf(&w, "],\"Unauthd\":[")
	comma = false
	for c, _ := range d.unauthd {
		cj, err := c.MarshalJSON()
		if err != nil {
			return nil, err
		}
		if comma {
			fmt.Fprintf(&w, ",")
		}
		fmt.Fprintf(&w, "%s", cj)
		comma = true
	}
	fmt.Fprintf(&w, "],\"Telephones\":[")
	comma = false
	for _, t := range d.tels {
		tj, err := t.MarshalJSON()
		if err != nil {
			return nil, err
		}
		if comma {
			fmt.Fprintf(&w, ",")
		}
		fmt.Fprintf(&w, "%s", tj)
		comma = true
	}
	fmt.Fprintf(&w, "]}")
	return w.Bytes(), nil
}
Exemple #5
0
func (c *Core) marshalProfJSON() string { return misc.JSONQuote(prof.String()) }
Exemple #6
0
func (id Id) ToJSON() string { return misc.JSONQuote(id.Eye()) }