// WriteVal writes an arbitrary value to the buffer
556818
func (w *ByteWriter) WriteVal(val interface{}, offset int) (int, error) {
	if s, isString := val.(string); isString {
		return w.WriteString(s, offset)
	}

	buf := bytes.NewBuffer(make([]byte, 0))

	err := binary.Write(buf, byteOrder, val)
	if err != nil {
		return 0, err
	}

	return w.Write(buf.Bytes(), offset)
}
298432
func (p *TCompactProtocol) writeVarint64(n int64) (int, error) {
	varint64out := make([]byte, 10)
	idx := 0
	for {
		if (n & ^0x7F) == 0 {
			varint64out[idx] = byte(n)
			idx++
			break
		} else {
			varint64out[idx] = byte((n & 0x7F) | 0x80)
			idx++
			u := uint64(n)
			n = int64(u >> 7)
		}
	}
	return p.trans.Write(varint64out[0:idx])
}
1032308
func (w *Writer) Writef(format string, args ...interface{}) error {
	return w.Write(fmt.Sprintf(format, args...))
}
339806
func (b *Buffer) WriteTo(w io.Writer) (int64, error) {
	version := b.preOp()
	n, err := b.buf.WriteTo(w)
	b.postOp(version)
	return n, err
}
131367
func writeStructuredValue(buffer Buffer, v interface{}) {
	s, ok := v.(string)
	if !ok {
		s = fmt.Sprint(v)
	}

	for _, r := range []rune(s) {
		switch r {
		case '"':
			buffer.AppendRune('\\')
			buffer.AppendRune('"')
		case '\\':
			buffer.AppendRune('\\')
			buffer.AppendRune('\\')
		case ']':
			buffer.AppendRune('\\')
			buffer.AppendRune(']')
		default:
			buffer.AppendRune(r)
		}
	}
}
368487
func (stream *Stream) WriteInt32(nval int32) {
	var val uint32
	if nval < 0 {
		val = uint32(-nval)
		stream.buf = append(stream.buf, '-')
	} else {
		val = uint32(nval)
	}
	stream.WriteUint32(val)
}
369069
func (stream *Stream) WriteInt8(nval int8) {
	var val uint8
	if nval < 0 {
		val = uint8(-nval)
		stream.buf = append(stream.buf, '-')
	} else {
		val = uint8(nval)
	}
	stream.buf = writeFirstBuf(stream.buf, digits[val])
}
341667
func (b *ByteBuffer) WriteByte(c byte) error {
	b.B = append(b.B, c)
	return nil
}
1038445
func (this *Future) loadVal() *futureVal {
	r := atomic.LoadPointer(&this.val)
	return (*futureVal)(r)
}
1324030
func (d *Diskv) WriteString(key string, val string) error {
	return d.Write(key, []byte(val))
}
747911
func WriteL(w io.Writer, bs ...[]byte) (n int, err error) {
	var c int
	for i := range bs {
		if c, err = w.Write(bs[i]); err == nil {
			n += c
		} else {
			break
		}
	}

	return
}
546204
func (bw *Writer) WriteValue(v wire.Value) error {
	switch v.Type() {
	case wire.TBool:
		if v.GetBool() {
			return bw.writeByte(1)
		}
		return bw.writeByte(0)

	case wire.TI8:
		return bw.writeByte(byte(v.GetI8()))

	case wire.TDouble:
		value := math.Float64bits(v.GetDouble())
		return bw.writeInt64(int64(value))

	case wire.TI16:
		return bw.writeInt16(v.GetI16())

	case wire.TI32:
		return bw.writeInt32(v.GetI32())

	case wire.TI64:
		return bw.writeInt64(v.GetI64())

	case wire.TBinary:
		b := v.GetBinary()
		if err := bw.writeInt32(int32(len(b))); err != nil {
			return err
		}
		return bw.write(b)

	case wire.TStruct:
		return bw.writeStruct(v.GetStruct())

	case wire.TMap:
		return bw.writeMap(v.GetMap())

	case wire.TSet:
		return bw.writeSet(v.GetSet())

	case wire.TList:
		return bw.writeList(v.GetList())

	default:
		return fmt.Errorf("unknown ttype %v", v.Type())
	}
}
812613
func (e *Engine) WriteValues(values map[string][]Value) error {
	e.mu.RLock()
	defer e.mu.RUnlock()

	if err := e.Cache.WriteMulti(values); err != nil {
		return err
	}

	return nil
}
467109
func (b *ByteBuffer) WriteString(s string) (int, error) {
	b.B = append(b.B, s...)
	return len(s), nil
}
133898
func (l *PacketIntervalList) insertValue(v PacketInterval, at *PacketIntervalElement) *PacketIntervalElement {
	return l.insert(&PacketIntervalElement{Value: v}, at)
}
609814
func (nw *NullIO) Write(v []byte) (int, error) {
	return len(v), nil
}
560350
func (buf *Buffer) Write(b []byte) (int, error) {
	buf.bytes = append(buf.bytes, b...)
	return len(b), nil
}