func (sw *TReader) structAuto(r *marshal.Reader, v reflect.Value) { if !v.CanSet() { sw.structFixed(r, v) return } l := r.IntUint32() flds := sw.Reader.Flds switch sw.Tail { /*case NoTail: if l < len(flds) { r.Err = fmt.Errorf("Wrong field count: expect %d, got %d", len(flds), l) return }*/ case Tail, TailSplit: if l < len(flds)-1 { break /*r.Err = fmt.Errorf("Wrong field count: expect at least %d, got %d", len(flds)-1, l) return*/ } tail := l - len(flds) + 1 last := flds[len(flds)-1] if sw.Tail == TailSplit { llast := len(last.Flds) tail /= llast } last.TReader.SetCount(v.Field(last.I), tail) } sw.structRead(r, l, v) }
func (sw *TReader) structFixed(r *marshal.Reader, v reflect.Value) { l := r.IntUint32() /*flds := sw.Reader.Flds switch sw.Tail { case NoTail: if l < len(flds) { r.Err = fmt.Errorf("Wrong field count: expect %d, got %d", len(flds), l) return } case Tail: need := len(flds) - 1 + v.Field(flds[len(flds)-1].I).Len() if l < need { r.Err = fmt.Errorf("Wrong field count: expect %d, got %d", need, l) return } case TailSplit: last := flds[len(flds)-1] need := len(flds) - 1 + v.Field(last.I).Len()*len(last.TReader.Flds) if l <= need { r.Err = fmt.Errorf("Wrong field count: expect %d, got %d", need, l) return } }*/ sw.structRead(r, l, v) }
func ReadSizedTuple(r *marshal.Reader, i interface{}) error { sz := r.IntUint32() if r.Err == nil { rd := marshal.Reader{Body: r.Slice(sz + 4)} r.Err = ReadRawTuple(&rd, i) } return r.Err }
func (t *TReader) sliceFixed(r *marshal.Reader, v reflect.Value) { if l := r.IntUint32(); l >= v.Len() { for i := 0; i < l; i++ { t.Reader.Elem.WithSize(r, v.Index(i), (*marshal.Reader).Intvar) } } else { r.Err = fmt.Errorf("Wrong field count: expect %d, got %d", v.Len(), l) } }
func (t *TReader) bytesAuto(r *marshal.Reader, v reflect.Value) { if !v.CanSet() { t.bytesFixed(r, v) return } if l := r.IntUint32(); l >= 1 { t.Reader.WithSize(r, v, (*marshal.Reader).Intvar) } else { r.Err = fmt.Errorf("Wrong field count: expect 1, got %d", l) } }
func (t *TReader) sliceAuto(r *marshal.Reader, v reflect.Value) { l := r.IntUint32() if v.CanSet() { v.Set(reflect.MakeSlice(v.Type(), l, l)) } else if l < v.Len() { r.Err = fmt.Errorf("Wrong field count: expect %d, got %d", v.Len(), l) return } for i := 0; i < l; i++ { t.Reader.Elem.WithSize(r, v.Index(i), (*marshal.Reader).Intvar) } }
func (t *TReader) string(r *marshal.Reader, v reflect.Value) { if l := r.Uint32(); l >= 1 { sz := r.Intvar() v.SetString(r.String(sz)) } else { r.Err = fmt.Errorf("Wrong field count: expect 1, got %d", l) } }
func oneFieldTuple(r *marshal.Reader, sz int) bool { var l, s int if l = r.IntUint32(); l >= 1 { if s = r.Intvar(); s == sz { return true } else { r.Err = fmt.Errorf("Wrong field size: expect 1, got %d", l) } } else { r.Err = fmt.Errorf("Wrong field count: expect 1, got %d", l) } return false }