Example #1
0
// WriteTo satifies io.WriterTo interface. TypeId is not encoded.
func (l *List) WriteTo(w io.Writer) (n int64, err error) {
	var nn int64

	// Write TagType prefix
	tt := types.Int8(l.Typ)
	if nn, err = tt.WriteTo(w); err != nil {
		return
	}
	n += nn

	length := types.Int32(len(l.Value))
	if nn, err = length.WriteTo(w); err != nil {
		return
	}
	n += nn

	for _, tag := range l.Value {
		if nn, err = tag.WriteTo(w); err != nil {
			return
		}
		n += nn
	}

	return
}
Example #2
0
func NewIntArray(s []int32) *IntArray {
	b := &IntArray{
		Value: make([]types.Int32, len(s)),
	}
	for index, elem := range s {
		b.Value[index] = types.Int32(elem)
	}
	return b
}
Example #3
0
func (rw ReadWriter) WriteInt32(w io.Writer, value int32) {
	if rw.Err != nil {
		return
	}

	t := types.Int32(value)
	n, err := t.WriteTo(w)
	if err != nil {
		rw.Err = fmt.Errorf("WriteInt32: %v", err)
		return
	}
	rw.N += n
}
Example #4
0
// WriteTo satifies io.WriterTo interface. TypeId is not encoded.
func (arr *IntArray) WriteTo(w io.Writer) (n int64, err error) {
	var nn int64

	// Write length-prefix
	var length = types.Int32(len(arr.Value))
	nn, err = length.WriteTo(w)
	if err != nil {
		return
	}
	n += nn

	// Then write int array
	for _, tag := range arr.Value {
		nn, err = tag.WriteTo(w)
		if err != nil {
			return
		}
		n += nn
	}
	return
}