@@ -211,27 +211,23 @@ func (t BitType_) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqltypes.Va
211211 return sqltypes .MakeTrusted (sqltypes .Bit , val ), nil
212212}
213213
214- // ToSQLValue implements Type2 interface.
214+ // ToSQLValue implements ValueType interface.
215215func (t BitType_ ) ToSQLValue (ctx * sql.Context , v sql.Value , dest []byte ) (sqltypes.Value , error ) {
216216 if v .IsNull () {
217217 return sqltypes .NULL , nil
218218 }
219219
220+ // Trim/Pad result to the appropriate length
220221 numBytes := t .numOfBits / 8
221222 if t .numOfBits % 8 != 0 {
222223 numBytes += 1
223224 }
224-
225- if uint8 (len (v .Val )) < numBytes {
226- // already in little endian, so just pad with trailing 0s
227- for i := uint8 (len (v .Val )); i <= t .numOfBits / 8 ; i ++ {
228- v .Val = append (v .Val , 0 )
229- }
230- } else {
231- v .Val = v .Val [:numBytes ]
225+ for i := uint8 (len (v .Val )); i < numBytes ; i ++ {
226+ v .Val = append (v .Val , 0 )
232227 }
228+ v .Val = v .Val [:numBytes ]
233229
234- // TODO: for whatever reason, TestTypesOverWire only works when this is a deep copy?
230+ // TODO: for whatever reason TestTypesOverWire only works when this is a deep copy?
235231 dest = append (dest , v .Val ... )
236232 // want the results in big endian
237233 for i , j := 0 , len (dest )- 1 ; i < j ; i , j = i + 1 , j - 1 {
0 commit comments