InitElts initialized a.Elts, by encoding elements in to bytes. Since 0.2.0
(elts interface{}, encoder encode.Encoder)
| 114 | // |
| 115 | // Since 0.2.0 |
| 116 | func (a *Base) InitElts(elts interface{}, encoder encode.Encoder) (int, error) { |
| 117 | |
| 118 | rElts := reflect.ValueOf(elts) |
| 119 | n := rElts.Len() |
| 120 | eltsize := encoder.GetEncodedSize(nil) |
| 121 | sz := eltsize * n |
| 122 | |
| 123 | b := make([]byte, 0, sz) |
| 124 | for i := 0; i < n; i++ { |
| 125 | ee := rElts.Index(i).Interface() |
| 126 | bs := encoder.Encode(ee) |
| 127 | b = append(b, bs...) |
| 128 | } |
| 129 | a.Elts = b |
| 130 | |
| 131 | return n, nil |
| 132 | } |
| 133 | |
| 134 | // Get retrieves the value at "idx" and return it. |
| 135 | // If this array has a value at "idx" it returns the value and "true", |
no test coverage detected