예제 #1
0
파일: writer.go 프로젝트: moxian/go-iproto
func (sw *TWriter) structWriter(w *marshal.Writer, v reflect.Value) {
	w.IntUint32(sw.structCnt(v))
	flds := sw.Writer.Flds
	n := len(flds)
	if sw.Tail != NoTail {
		n -= 1
	}
	for i := 0; i < n; i++ {
		fs := &flds[i]
		fs.WithSize(w, v.Field(fs.I), (*marshal.Writer).Intvar)
	}
	switch sw.Tail {
	case NoTail:
	case Tail:
		fs := &flds[n]
		fv := v.Field(n)
		l := fv.Len()
		for i := 0; i < l; i++ {
			val := fv.Index(i)
			fs.WithSize(w, val, (*marshal.Writer).Intvar)
		}
	case TailSplit:
		fs := &flds[n]
		fv := v.Field(n)
		l := fv.Len()
		fss := fs.TWriter.Flds
		fl := len(fss)
		for i := 0; i < l; i++ {
			str := fv.Index(i)
			for j := 0; j < fl; j++ {
				fss[i].WithSize(w, str.Field(i), (*marshal.Writer).Intvar)
			}
		}
	}
}
예제 #2
0
파일: modify.go 프로젝트: moxian/go-iproto
func (i DeleteReq) IWrite(w *marshal.Writer) {
	w.Uint32(i.Space)
	var flags uint32
	if i.Return {
		flags = 1
	}
	w.Uint32(flags)
	WriteTuple(w, i.Key)
}
예제 #3
0
파일: modify.go 프로젝트: moxian/go-iproto
func (i StoreReq) IWrite(w *marshal.Writer) {
	w.Uint32(i.Space)
	var flags uint32
	if i.Return {
		flags = 1
	}
	flags |= uint32(i.Mode) << 1
	w.Uint32(flags)
	WriteTuple(w, i.Tuple)
}
예제 #4
0
파일: modify.go 프로젝트: moxian/go-iproto
func (u UpdateReq) IWrite(w *marshal.Writer) {
	w.Uint32(u.Space)
	var flags uint32
	if u.Return {
		flags = 1
	}
	w.Uint32(flags)
	WriteTuple(w, u.Key)
	w.Write(u.Ops)
}
예제 #5
0
파일: request.go 프로젝트: moxian/go-iproto
func (b Body) IWrite(w *marshal.Writer) {
	w.Bytes([]byte(b))
}
예제 #6
0
파일: writer.go 프로젝트: moxian/go-iproto
func WriteTuple(w *marshal.Writer, i interface{}) {
	switch o := i.(type) {
	case nil:
		return
	case uint8:
		w.Uint32(1)
		w.Uint8(1)
		w.Uint8(o)
	case int8:
		w.Uint32(1)
		w.Uint8(1)
		w.Int8(o)
	case uint16:
		w.Uint32(1)
		w.Uint8(2)
		w.Uint16(o)
	case int16:
		w.Uint32(1)
		w.Uint8(2)
		w.Int16(o)
	case uint32:
		w.Uint32(1)
		w.Uint8(4)
		w.Uint32(o)
	case int32:
		w.Uint32(1)
		w.Uint8(4)
		w.Int32(o)
	case uint64:
		w.Uint32(1)
		w.Uint8(8)
		w.Uint64(o)
	case int64:
		w.Uint32(1)
		w.Uint8(8)
		w.Int64(o)
	case float32:
		w.Uint32(1)
		w.Uint8(4)
		w.Float32(o)
	case float64:
		w.Uint32(1)
		w.Uint8(8)
		w.Float64(o)
	case string:
		w.Uint32(1)
		w.Intvar(len(o))
		w.String(o)
	case []byte:
		w.Uint32(1)
		w.Intvar(len(o))
		w.Bytes(o)
	case []interface{}:
		w.IntUint32(len(o))
		for _, v := range o {
			w.WriteWithSize(v, (*marshal.Writer).Intvar)
		}
	default:
		val := reflect.ValueOf(i)
		rt := val.Type()
		wr := writer(rt)
		wr.Write(w, val)
	}
	return
}
예제 #7
0
파일: select.go 프로젝트: moxian/go-iproto
func (s SelectReq) IWrite(w *marshal.Writer) {
	w.Uint32(s.Space)
	w.Uint32(s.Index)
	w.Uint32(s.Offset)
	cnt := CountKeys(s.Keys)
	if s.Limit >= 0 {
		w.Int32(s.Limit)
	} else if s.Limit == SelectN {
		w.Int32(int32(cnt))
	} else {
		w.Int32(1<<31 - 1)
	}
	w.IntUint32(cnt)
	WriteKeys(w, s.Keys)
}
예제 #8
0
파일: modify.go 프로젝트: moxian/go-iproto
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)
	}
}