Exemplo n.º 1
0
func (o Op) IWrite(w *marshal.Writer) {
	w.Write(o.Field)
	if o.Op <= 7 {
		w.Write(o.Op)
	} else {
		w.Write(opmap[o.Op])
	}
	switch v := o.Val.(type) {
	case uint32:
		w.Int8(4)
		w.Uint32(v)
	case uint64:
		w.Int8(8)
		w.Uint64(v)
	case int32:
		w.Int8(4)
		w.Int32(v)
	case int64:
		w.Int8(8)
		w.Int64(v)
	case []byte:
		w.Intvar(len(v))
		w.Bytes(v)
	case string:
		w.Intvar(len(v))
		w.String(v)
	default:
		val := reflect.ValueOf(v)
		wr := marshal.WriterFor(val.Type())
		wr.WithSize(w, val, (*marshal.Writer).Intvar)
	}
}
Exemplo n.º 2
0
func _writer(rt reflect.Type) (wr *TWriter) {
	rtid := reflect.ValueOf(rt).Pointer()
	if wr = wss[rtid]; wr == nil {
		wr = &TWriter{Writer: marshal.WriterFor(rt)}
		wss[rtid] = wr
		wr.Fill()
	}
	return
}