// The workhorse of writeFieldBegin. It has the option of doing a
// 'type override' of the type header. This is used specifically in the
// boolean field case.
964271
func (p *TCompactProtocol) writeFieldBeginInternal(name string, typeId TType, id int16, typeOverride byte) (int, error) {
	// short lastField = lastField_.pop();

	// if there's a type override, use that.
	var typeToWrite byte
	if typeOverride == 0xFF {
		typeToWrite = byte(p.getCompactType(typeId))
	} else {
		typeToWrite = typeOverride
	}
	// check if we can use delta encoding for the field id
	fieldId := int(id)
	written := 0
	if fieldId > p.lastFieldId && fieldId-p.lastFieldId <= 15 {
		// write them together
		written, err := p.writeByteDirect(byte((fieldId-p.lastFieldId)<<4) | typeToWrite)
		if err != nil {
			return written, err
		}
	} else {
		// write them separate
		n, err := p.writeByteDirect(typeToWrite)
		if err != nil {
			return n, err
		}
		err = p.WriteI16(id)
		written = n + 2
		if err != nil {
			return written, err
		}
	}

	p.lastFieldId = fieldId
	// p.lastField.Push(field.id);
	return written, nil
}
1195648
func (w *http2responseWriter) WriteHeader(code int) {
	if atomic.CompareAndSwapInt32(w.code, 0, int32(code)) {
		w.ResponseWriter.WriteHeader(code)
	}
}
325397
func (f *FieldSetType) Field(name string) fields.FieldInterface {
	ind, ok := f.fieldMap[name]
	if !ok {
		return &fields.Field{}
	}
	return f.fields[ind].(fields.FieldInterface)
}
245186
func writeTypes(args *internal.ArgType) error {
	var err error

	out := internal.TBufSlice(args.Generated)

	// sort segments
	sort.Sort(out)

	// loop, writing in order
	for _, t := range out {
		var f *os.File

		// skip when in append and type is XO
		if args.Append && t.TemplateType == internal.XOTemplate {
			continue
		}

		// check if generated template is only whitespace/empty
		bufStr := strings.TrimSpace(t.Buf.String())
		if len(bufStr) == 0 {
			continue
		}

		// get file and filename
		f, err = getFile(args, &t)
		if err != nil {
			return err
		}

		// should only be nil when type == xo
		if f == nil {
			continue
		}

		// write segment
		if !args.Append || (t.TemplateType != internal.TypeTemplate && t.TemplateType != internal.QueryTypeTemplate) {
			_, err = t.Buf.WriteTo(f)
			if err != nil {
				return err
			}
		}
	}

	// build goimports parameters, closing files
	params := []string{"-w"}
	for k, f := range files {
		params = append(params, k)

		// close
		err = f.Close()
		if err != nil {
			return err
		}
	}

	// process written files with goimports
	output, err := exec.Command("goimports", params...).CombinedOutput()
	if err != nil {
		return errors.New(string(output))
	}

	return nil
}
358837
func WriteClientBinary(w io.Writer, p []byte) error {
	return WriteClientMessage(w, ws.OpBinary, p)
}
1145099
func (m *Table) AddFieldType(name string, valType value.ValueType) {
	m.AddField(&Field{FieldPb: FieldPb{Type: uint32(valType), Name: name}})
}
262758
func OptFieldTypeBool() FieldOption {
	return func(fo *FieldOptions) error {
		if fo.Type != "" {
			return errors.Errorf("field type is already set to: %s", fo.Type)
		}
		fo.Type = FieldTypeBool
		return nil
	}
}
1334688
func (p *TCompactProtocol) WriteBinary(bin []byte) error {
	_, e := p.writeVarint32(int32(len(bin)))
	if e != nil {
		return NewTProtocolException(e)
	}
	if len(bin) > 0 {
		_, e = p.trans.Write(bin)
		return NewTProtocolException(e)
	}
	return nil
}
866194
func (p *TCompactProtocol) writeCollectionBegin(elemType TType, size int) (int, error) {
	if size <= 14 {
		return p.writeByteDirect(byte(int32(size<<4) | int32(p.getCompactType(elemType))))
	}
	n, err := p.writeByteDirect(0xf0 | byte(p.getCompactType(elemType)))
	if err != nil {
		return n, err
	}
	m, err := p.writeVarint32(int32(size))
	return n + m, err
}
190763
func (b *BaseQueryBuilder) WriteHead(buffer *bytes.Buffer) {
	buffer.WriteString(b.head)
}
331125
func (builder *MultipartBuilder) WriteFieldAsJSON(partName string, data interface{}, base64Encode bool) error {
	jsonBytes, err := json.Marshal(data)
	if err != nil {
		return err
	}

	header := textproto.MIMEHeader{}
	header.Add(hum.HeaderContentDisposition, fmt.Sprintf(`form-data; name="%s"`, partName))
	header.Add(hum.HeaderContentType, hum.ContentTypeAppJsonUtf8)
	if base64Encode {
		header.Add(hum.HeaderContentTransferEncoding, "base64")
	}

	partWriter, err := builder.Writer.CreatePart(header)
	if err != nil {
		return err
	}

	if base64Encode {
		str := base64.StdEncoding.EncodeToString(jsonBytes)
		_, err = bytes.NewBuffer([]byte(str)).WriteTo(partWriter)
	} else {
		_, err = bytes.NewBuffer(jsonBytes).WriteTo(partWriter)
	}
	return err
}
1277567
func BoolField(name string, value bool) FieldOpt {
	return func(em *eventMetadata, ed *eventData) {
		em.writeField(name, inTypeUint8, outTypeBoolean, 0)
		bool8 := uint8(0)
		if value {
			bool8 = uint8(1)
		}
		ed.writeUint8(bool8)
	}
}
1145631
func (m *MultipartStreamer) WriteFields(fields map[string]string) error {
	var err error

	for key, value := range fields {
		err = m.bodyWriter.WriteField(key, value)
		if err != nil {
			return err
		}
	}

	return nil
}
1093846
func (typeProperty *TypeProperty) FieldName() string {
	propertyName := typeProperty.Name
	if propertyName == "$ref" {
		return "XRef"
	}
	return strings.Title(snakeCaseToCamelCase(propertyName))
}
1317046
func (dt *DbfTable) Write(row int, spec interface{}) int {
	s := reflect.ValueOf(spec)
	if s.Kind() == reflect.Ptr {
		s = s.Elem()
	}
	if s.Kind() != reflect.Struct {
		panic("dbf: spec parameter must be a struct")
	}

	typeOfSpec := s.Type()
	for i := 0; i < s.NumField(); i++ {
		f := s.Field(i)
		if typeOfSpec.Field(i).PkgPath != "" || typeOfSpec.Field(i).Anonymous {
			continue // ignore unexported or embedded fields
		}

		alt := typeOfSpec.Field(i).Tag.Get("dbf")
		// ignore '-' tags
		if alt == "-" {
			continue
		}

		val := ""
		switch f.Kind() {
		default:
			panic("dbf: unsupported type for database table schema, use dash to omit")
		case reflect.String:
			val = f.String()
		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
			reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
			val = fmt.Sprintf("%d", f.Int())
		case reflect.Bool:
			val = "f"
			if f.Bool() {
				val = "t"
			}
		case reflect.Float32, reflect.Float64:
			val = fmt.Sprintf("%f", f.Float())
		}

		//fmt.Println(typeOfSpec.Field(i).Name)
		dt.SetFieldValueByName(row, typeOfSpec.Field(i).Name, val)
	}
	return row
}
29994
func (rwops *RWops) WriteBE16(value uint16) uint {
	if rwops == nil {
		return 0
	}
	return uint(C.SDL_WriteBE16(rwops.cptr(), C.Uint16(value)))
}
100149
func (p *printer) Field(field *descriptor.FieldDescriptorProto) {
	p.MaybeLeadingComments(field)
	if descutil.Repeated(field) {
		p.Printf("repeated ")
	}

	typeName := fieldTypeName[field.GetType()]
	if typeName == "" {
		typeName = p.shorten(field.GetTypeName())
	}
	if typeName == "" {
		typeName = "<unsupported type>"
	}
	p.Printf("%s %s = %d;\n", typeName, field.GetName(), field.GetNumber())
}