本文整理匯總了Golang中github.com/funny-falcon/go-iproto/marshal.Reader類的典型用法代碼示例。如果您正苦於以下問題:Golang Reader類的具體用法?Golang Reader怎麽用?Golang Reader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Reader類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: structAuto
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)
}
示例2: structFixed
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)
}
示例3: ReadSizedTuple
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
}
示例4: sliceFixed
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)
}
}
示例5: bytesAuto
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)
}
}
示例6: sliceAuto
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)
}
}
示例7: string
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)
}
}
示例8: oneFieldTuple
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
}