// GetCompressedMasterJSON assembles a CompressedMasterJSON object from the
// provided MasterRequest.
168579
func (s *Service) GetCompressedMasterJSON(c context.Context, req *milo.MasterRequest) (
	*milo.CompressedMasterJSON, error) {

	if req.Name == "" {
		return nil, status.Errorf(codes.InvalidArgument, "No master specified")
	}

	apiUsage.Add(c, 1, "GetCompressedMasterJSON", req.Name, "", req.ExcludeDeprecated, req.NoEmulation)

	cu := auth.CurrentUser(c)
	logging.Debugf(c, "%s is making a master request for %s", cu.Identity, req.Name)

	if err := buildstore.CanAccessMaster(c, req.Name); err != nil {
		return nil, err
	}

	master, err := buildstore.GetMaster(c, req.Name, true)

	switch code := grpcutil.Code(err); {
	case code == codes.NotFound, code == codes.PermissionDenied:
		return nil, errNotFoundGRPC
	case err != nil:
		return nil, err
	}

	for _, builder := range master.Builders {
		// Nobody uses PendingBuildStates.
		// Exclude them from the response
		// because they are hard to emulate.
		builder.PendingBuildStates = nil
	}

	if req.ExcludeDeprecated {
		excludeDeprecatedFromMaster(&master.Master)
	}

	// Compress it.
	gzbs := bytes.Buffer{}
	gsw := gzip.NewWriter(&gzbs)
	cw := iotools.CountingWriter{Writer: gsw}
	e := json.NewEncoder(&cw)
	if err := e.Encode(master); err != nil {
		gsw.Close()
		return nil, err
	}
	gsw.Close()

	logging.Infof(c, "Returning %d bytes", cw.Count)

	return &milo.CompressedMasterJSON{
		Internal: master.Internal,
		Modified: google.NewTimestamp(master.Modified),
		Data:     gzbs.Bytes(),
	}, nil
}
1002219
func (bA *BitArray) MarshalJSON() ([]byte, error) {
	if bA == nil {
		return []byte("null"), nil
	}

	bA.mtx.Lock()
	defer bA.mtx.Unlock()

	bits := `"`
	for i := 0; i < bA.Bits; i++ {
		if bA.getIndex(i) {
			bits += `x`
		} else {
			bits += `_`
		}
	}
	bits += `"`
	return []byte(bits), nil
}
1090055
func (e EncodedHeader) MarshalJSON() ([]byte, error) {
	buf, err := e.Base64Encode()
	if err != nil {
		return nil, errors.Wrap(err, "failed to base64 encode encoded header")
	}
	return json.Marshal(string(buf))
}
451454
func (u *Unstructured) MarshalJSON() ([]byte, error) {
	var buf bytes.Buffer
	err := UnstructuredJSONScheme.Encode(u, &buf)
	return buf.Bytes(), err
}
928276
func (mls MultiLineString) MarshalJSON() ([]byte, error) {
	return json.Marshal(Geometry{Coordinates: orb.MultiLineString(mls)})
}
1299492
func (r *SearchRequest) MarshalJSON() ([]byte, error) {
	root := make(map[string]interface{})

	root["size"] = r.Size
	if len(r.Sort) > 0 {
		root["sort"] = r.Sort
	}

	for key, value := range r.CustomProps {
		root[key] = value
	}

	root["query"] = r.Query

	if len(r.Aggs) > 0 {
		root["aggs"] = r.Aggs
	}

	return json.Marshal(root)
}
1217538
func (v Attachment) MarshalJSON() ([]byte, error) {
	w := jwriter.Writer{}
	easyjsonCce3d1beEncodeGithubComMailgunMailgunGoEvents10(&w, v)
	return w.Buffer.BuildBytes(), w.Error
}
237808
func (o ObjectInfo) IsCompressed() bool {
	_, ok := o.UserDefined[ReservedMetadataPrefix+"compression"]
	return ok
}
512997
func (v Delivered) MarshalJSON() ([]byte, error) {
	w := jwriter.Writer{}
	easyjson692db02bEncodeGithubComMailgunMailgunGoEvents14(&w, v)
	return w.Buffer.BuildBytes(), w.Error
}
1345974
func (p *Repository) GetJSON() string {
	p.Mutex.RLock()
	defer p.Mutex.RUnlock()

	result := api.Rules{}
	for _, r := range p.rules {
		result = append(result, &r.Rule)
	}

	return JSONMarshalRules(result)
}
968163
func (v bulkUpdateRequestCommandOp) MarshalJSON() ([]byte, error) {
	w := jwriter.Writer{}
	easyjson1ed00e60EncodeGithubComOlivereElastic(&w, v)
	return w.Buffer.BuildBytes(), w.Error
}
1198072
func (v bulkIndexRequestCommand) MarshalJSON() ([]byte, error) {
	w := jwriter.Writer{}
	easyjson9de0fcbfEncodeGithubComOlivereElastic1(&w, v)
	return w.Buffer.BuildBytes(), w.Error
}
1371458
func (v ListMemberUploaded) MarshalJSON() ([]byte, error) {
	w := jwriter.Writer{}
	easyjson692db02bEncodeGithubComMailgunMailgunGoEvents9(&w, v)
	return w.Buffer.BuildBytes(), w.Error
}
589183
func (v ListMemberUploadError) MarshalJSON() ([]byte, error) {
	w := jwriter.Writer{}
	easyjson692db02bEncodeGithubComMailgunMailgunGoEvents10(&w, v)
	return w.Buffer.BuildBytes(), w.Error
}
878515
func (c Config) MarshalJSON() ([]byte, error) {
	m := map[string]interface{}{
		"version":  c.Version,
		"services": c.Services,
	}

	if len(c.Networks) > 0 {
		m["networks"] = c.Networks
	}
	if len(c.Volumes) > 0 {
		m["volumes"] = c.Volumes
	}
	if len(c.Secrets) > 0 {
		m["secrets"] = c.Secrets
	}
	if len(c.Configs) > 0 {
		m["configs"] = c.Configs
	}
	for k, v := range c.Extras {
		m[k] = v
	}
	return json.Marshal(m)
}
1108433
func (d *MasterDaemon) getMasterInfo() (map[string]interface{}, error) {
	info := make(map[string]interface{})

	// get local ip
	localIP, err := netutils.GetDefaultAddr()
	if err != nil {
		return nil, errors.New("error getting local IP address")
	}

	// get current holder of master lock
	leader := leaderLock.GetHolder()
	if leader == "" {
		return nil, errors.New("leader not found")
	}

	// Get all netplugin services
	srvList, err := d.objdbClient.GetService("netplugin")
	if err != nil {
		log.Errorf("Error getting netplugin nodes. Err: %v", err)
		return nil, err
	}

	// Add each node
	pluginNodes := []string{}
	for _, srv := range srvList {
		pluginNodes = append(pluginNodes, srv.HostAddr)
	}

	// Get all netmaster services
	srvList, err = d.objdbClient.GetService("netmaster")
	if err != nil {
		log.Errorf("Error getting netmaster nodes. Err: %v", err)
		return nil, err
	}

	// Add each node
	masterNodes := []string{}
	for _, srv := range srvList {
		masterNodes = append(masterNodes, srv.HostAddr)
	}

	// setup info map
	info["local-ip"] = localIP
	info["leader-ip"] = leader
	info["current-state"] = d.currState
	info["netplugin-nodes"] = pluginNodes
	info["netmaster-nodes"] = masterNodes

	return info, nil
}
495139
func (gat GetAllTarget) MarshalJSON() ([]byte, error) {
	switch gat {
	case GetAllProject:
		return projectJSON, nil
	case GetAllRef:
		return refJSON, nil
	default:
		return nil, errors.Reason("unknown GetAllTarget: %v", gat).Err()
	}
}