// A more json.Marshal like version of WriteOption.
162003
func DHCPMarshalOption(o DHCPOption) (out []byte, err error) {
	switch o.OptionType() {
	case DHCP_OPT_PAD, DHCP_OPT_END:
		out = []byte{o.OptionType()}
	default:
		dlen := len(o.Bytes())
		if dlen > 253 {
			err = errors.New("Data too long to marshal")
		} else {
			out = make([]byte, dlen+2)
			out[0], out[1] = o.OptionType(), byte(dlen)
			copy(out[2:], o.Bytes())
		}
	}
	return
}
221053
func (c *jsonCodec) Write(ctx context.Context, v interface{}) error {
	c.encMu.Lock()
	defer c.encMu.Unlock()

	deadline, ok := ctx.Deadline()
	if !ok {
		deadline = time.Now().Add(defaultWriteTimeout)
	}
	c.conn.SetWriteDeadline(deadline)
	return c.encode(v)
}
279285
func (p *PostProcessor) MarshalJSON() ([]byte, error) {
	// Early exit for simple definitions
	if len(p.Config) == 0 && len(p.OnlyExcept.Only) == 0 && len(p.OnlyExcept.Except) == 0 && p.KeepInputArtifact == nil {
		return json.Marshal(p.Type)
	}

	// Avoid recursion
	type PostProcessor_ PostProcessor
	out, _ := json.Marshal(PostProcessor_(*p))

	var m map[string]json.RawMessage
	_ = json.Unmarshal(out, &m)

	// Flatten Config
	delete(m, "config")
	for k, v := range p.Config {
		out, _ = json.Marshal(v)
		m[k] = out
	}

	return json.Marshal(m)
}
595759
func DHCPWriteOption(w io.Writer, a DHCPOption) (n int, err error) {
	out, err := DHCPMarshalOption(a)
	if err == nil {
		n, err = w.Write(out)
	}
	return
}
67365
func WriteJSON(w http.ResponseWriter, v interface{}) error {
	b, err := json.MarshalIndent(v, "", "  ")
	if err != nil {
		return err
	}

	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	w.Write(b)
	return nil
}
96355
func (r *request) setWriteOptions(q *WriteOptions) {
	if q == nil {
		return
	}
	if q.Datacenter != "" {
		r.params.Set("dc", q.Datacenter)
	}
	if q.Token != "" {
		r.params.Set("token", q.Token)
	}
}
632127
func NewOption(name string, params map[string]string) Option {
	p := Parameters{}
	for k, v := range params {
		p.Set([]byte(k), []byte(v))
	}
	return Option{
		Name:       []byte(name),
		Parameters: p,
	}
}
1069055
func (w *DecodedJSONMessageWriter) Write(b []byte) (int, error) {
	err := jsonmessage.DisplayJSONMessagesStream(bytes.NewReader(b), w.w, w.fd, false, nil)
	if err != nil {
		if err, ok := err.(*jsonmessage.JSONError); ok {
			w.err = err
			return len(b), nil
		}
	}
	return len(b), err
}
334880
func (o *InsidePolygonOption) UnmarshalJSON(data []byte) error {
	if string(data) == "null" {
		return nil
	}

	var polygons [][]float64
	if err := json.Unmarshal(data, &polygons); err == nil {
		o.polygons = polygons
		return nil
	}

	var coordinates string
	if err := json.Unmarshal(data, &coordinates); err == nil {
		o.coordinates = coordinates
		return nil
	}

	return errs.ErrJSONDecode(data, "InsidePolygon")
}
96738
func (g *Gnostic) writeJSONYAMLOutput(message proto.Message) {
	// Convert the OpenAPI document into an exportable MapSlice.
	var rawInfo yaml.MapSlice
	var ok bool
	var err error
	if g.sourceFormat == SourceFormatOpenAPI2 {
		document := message.(*openapi_v2.Document)
		rawInfo, ok = document.ToRawInfo().(yaml.MapSlice)
		if !ok {
			rawInfo = nil
		}
	} else if g.sourceFormat == SourceFormatOpenAPI3 {
		document := message.(*openapi_v3.Document)
		rawInfo, ok = document.ToRawInfo().(yaml.MapSlice)
		if !ok {
			rawInfo = nil
		}
	} else if g.sourceFormat == SourceFormatDiscovery {
		document := message.(*discovery_v1.Document)
		rawInfo, ok = document.ToRawInfo().(yaml.MapSlice)
		if !ok {
			rawInfo = nil
		}
	}
	// Optionally write description in yaml format.
	if g.yamlOutputPath != "" {
		var bytes []byte
		if rawInfo != nil {
			bytes, err = yaml.Marshal(rawInfo)
			if err != nil {
				fmt.Fprintf(os.Stderr, "Error generating yaml output %s\n", err.Error())
			}
			writeFile(g.yamlOutputPath, bytes, g.sourceName, "yaml")
		} else {
			fmt.Fprintf(os.Stderr, "No yaml output available.\n")
		}
	}
	// Optionally write description in json format.
	if g.jsonOutputPath != "" {
		var bytes []byte
		if rawInfo != nil {
			bytes, _ = jsonwriter.Marshal(rawInfo)
			if err != nil {
				fmt.Fprintf(os.Stderr, "Error generating json output %s\n", err.Error())
			}
			writeFile(g.jsonOutputPath, bytes, g.sourceName, "json")
		} else {
			fmt.Fprintf(os.Stderr, "No json output available.\n")
		}
	}
}
561531
func (o *DistinctOption) UnmarshalJSON(data []byte) error {
	if string(data) == "null" {
		return nil
	}

	var i int
	if err := json.Unmarshal(data, &i); err == nil {
		o.value = i
		return nil
	}

	var b bool
	if err := json.Unmarshal(data, &b); err == nil {
		if b {
			o.value = 1
		} else {
			o.value = 0
		}
		return nil
	}

	return errs.ErrJSONDecode(data, "Distinct")
}
863097
func (s Style) WriteTextOptionsToRenderer(r Renderer) {
	r.SetClassName(s.GetClassName())
	r.SetFont(s.GetFont())
	r.SetFontColor(s.GetFontColor())
	r.SetFontSize(s.GetFontSize())
}
808456
func (o *TypoToleranceOption) UnmarshalJSON(data []byte) error {
	if string(data) == "null" {
		o.value = typoToleranceTrue
		return nil
	}

	var v string
	if err := json.Unmarshal(data, &v); err == nil {
		o.value = v
		return nil
	}

	var b bool
	if err := json.Unmarshal(data, &b); err == nil {
		o.value = fmt.Sprintf("%t", b)
		return nil
	}

	return errs.ErrJSONDecode(data, "TypoTolerance")
}
1363136
func WriteJSON(w io.Writer, v interface{}) error {
	data, err := json.Marshal(v)
	if err != nil {
		return err
	}
	_, err = w.Write(data)
	return err
}
34845
func (o *FieldOptions) MarshalJSON() ([]byte, error) {
	switch o.Type {
	case FieldTypeSet:
		return json.Marshal(struct {
			Type      string `json:"type"`
			CacheType string `json:"cacheType"`
			CacheSize uint32 `json:"cacheSize"`
			Keys      bool   `json:"keys"`
		}{
			o.Type,
			o.CacheType,
			o.CacheSize,
			o.Keys,
		})
	case FieldTypeInt:
		return json.Marshal(struct {
			Type string `json:"type"`
			Min  int64  `json:"min"`
			Max  int64  `json:"max"`
			Keys bool   `json:"keys"`
		}{
			o.Type,
			o.Min,
			o.Max,
			o.Keys,
		})
	case FieldTypeTime:
		return json.Marshal(struct {
			Type           string      `json:"type"`
			TimeQuantum    TimeQuantum `json:"timeQuantum"`
			Keys           bool        `json:"keys"`
			NoStandardView bool        `json:"noStandardView"`
		}{
			o.Type,
			o.TimeQuantum,
			o.Keys,
			o.NoStandardView,
		})
	case FieldTypeMutex:
		return json.Marshal(struct {
			Type      string `json:"type"`
			CacheType string `json:"cacheType"`
			CacheSize uint32 `json:"cacheSize"`
			Keys      bool   `json:"keys"`
		}{
			o.Type,
			o.CacheType,
			o.CacheSize,
			o.Keys,
		})
	case FieldTypeBool:
		return json.Marshal(struct {
			Type string `json:"type"`
		}{
			o.Type,
		})
	}
	return nil, errors.New("invalid field type")
}
559158
func WriteWithFS(options Options, fs afero.Fs) error {
	serviceFile := optionsToServiceFile(options)

	data, err := json.MarshalIndent(serviceFile, "", "  ")
	if err != nil {
		return err
	}

	serviceConfigPath := filepath.Join(options.Dir, "service.json")
	err = afero.WriteFile(fs, serviceConfigPath, data, 0644)

	if err != nil {
		return err
	}

	return nil
}
109825
func (s Slice) JSONString(options ...DumperOptions) (string, error) {
	buf := &bytes.Buffer{}
	var opt *DumperOptions
	if len(options) > 0 {
		opt = &options[0]
	}
	d := NewDumper(buf, opt)
	if err := d.Append(s); err != nil {
		return "", WithStack(err)
	}
	return buf.String(), nil
}