Skip to content

Commit

Permalink
Support [16]byte/[]byte typed scan/append for IPv6 column (#996)
Browse files Browse the repository at this point in the history
* support [16]byte/[]byte typed scan/append for IPv6 column

* resolve comments

* resolve comments
  • Loading branch information
crisismaple authored May 17, 2023
1 parent 958b917 commit 78780a8
Show file tree
Hide file tree
Showing 2 changed files with 233 additions and 86 deletions.
89 changes: 88 additions & 1 deletion lib/column/ipv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ func (col *IPv6) ScanRow(dest any, row int) error {
case **net.IP:
*d = new(net.IP)
**d = col.row(row)
case *[]byte:
*d = col.row(row)
case **[]byte:
*d = new([]byte)
**d = col.row(row)
case *proto.IPv6:
*d = col.col.Row(row)
case **proto.IPv6:
*d = new(proto.IPv6)
**d = col.col.Row(row)
case *[16]byte:
*d = col.col.Row(row)
case **[16]byte:
*d = new([16]byte)
**d = col.col.Row(row)
default:
return &ColumnConverterError{
Op: "ScanRow",
Expand Down Expand Up @@ -151,7 +166,6 @@ func (col *IPv6) Append(v any) (nulls []uint8, err error) {
case []net.IP:
nulls = make([]uint8, len(v))
for _, v := range v {
nulls = make([]uint8, len(v))
col.col.Append(proto.ToIPv6(netip.AddrFrom16(IPv6ToBytes(v))))
}
case []*net.IP:
Expand All @@ -165,6 +179,52 @@ func (col *IPv6) Append(v any) (nulls []uint8, err error) {
col.col.Append([16]byte{})
}
}
case [][]byte:
nulls = make([]uint8, len(v))
for _, v := range v {
col.col.Append(proto.ToIPv6(netip.AddrFrom16(IPv6ToBytes(v))))
}
case []*[]byte:
nulls = make([]uint8, len(v))
for i, v := range v {
switch {
case v != nil:
col.col.Append(proto.ToIPv6(netip.AddrFrom16(IPv6ToBytes(*v))))
default:
nulls[i] = 1
col.col.Append([16]byte{})
}
}
case [][16]byte:
for _, v := range v {
col.col.Append(v)
}
case []*[16]byte:
nulls = make([]uint8, len(v))
for i, v := range v {
switch {
case v != nil:
col.col.Append(*v)
default:
nulls[i] = 1
col.col.Append([16]byte{})
}
}
case []proto.IPv6:
for _, v := range v {
col.col.Append(v)
}
case []*proto.IPv6:
nulls = make([]uint8, len(v))
for i, v := range v {
switch {
case v != nil:
col.col.Append(*v)
default:
nulls[i] = 1
col.col.Append([16]byte{})
}
}
default:
return nil, &ColumnConverterError{
Op: "Append",
Expand Down Expand Up @@ -220,6 +280,33 @@ func (col *IPv6) AppendRow(v any) (err error) {
default:
col.col.Append([16]byte{})
}
case []byte:
col.col.Append(proto.ToIPv6(netip.AddrFrom16(IPv6ToBytes(v))))
case *[]byte:
switch {
case v != nil:
col.col.Append(proto.ToIPv6(netip.AddrFrom16(IPv6ToBytes(*v))))
default:
col.col.Append([16]byte{})
}
case [16]byte:
col.col.Append(v)
case *[16]byte:
switch {
case v != nil:
col.col.Append(*v)
default:
col.col.Append([16]byte{})
}
case proto.IPv6:
col.col.Append(v)
case *proto.IPv6:
switch {
case v != nil:
col.col.Append(*v)
default:
col.col.Append([16]byte{})
}
case nil:
col.col.Append([16]byte{})
default:
Expand Down
Loading

0 comments on commit 78780a8

Please sign in to comment.