Extract codecDecodeToTextFormat
This commit is contained in:
+1
-13
@@ -126,19 +126,7 @@ func (BoxCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target interfac
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c BoxCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c BoxCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if format == TextFormatCode {
|
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
||||||
return string(src), nil
|
|
||||||
} else {
|
|
||||||
box, err := c.DecodeValue(ci, oid, format, src)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
buf, err := c.Encode(ci, oid, TextFormatCode, box, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return string(buf), nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c BoxCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c BoxCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
|
|||||||
+1
-13
@@ -124,19 +124,7 @@ func (CircleCodec) PlanScan(ci *ConnInfo, oid uint32, format int16, target inter
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c CircleCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
func (c CircleCodec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
if format == TextFormatCode {
|
return codecDecodeToTextFormat(c, ci, oid, format, src)
|
||||||
return string(src), nil
|
|
||||||
} else {
|
|
||||||
circle, err := c.DecodeValue(ci, oid, format, src)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
buf, err := c.Encode(ci, oid, TextFormatCode, circle, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return string(buf), nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c CircleCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
func (c CircleCodec) DecodeValue(ci *ConnInfo, oid uint32, format int16, src []byte) (interface{}, error) {
|
||||||
|
|||||||
+3
-15
@@ -209,11 +209,7 @@ func (c Int2Codec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16
|
|||||||
}
|
}
|
||||||
|
|
||||||
var n int64
|
var n int64
|
||||||
scanPlan := c.PlanScan(ci, oid, format, &n, true)
|
err := codecScan(c, ci, oid, format, src, &n)
|
||||||
if scanPlan == nil {
|
|
||||||
return nil, fmt.Errorf("PlanScan did not find a plan")
|
|
||||||
}
|
|
||||||
err := scanPlan.Scan(ci, oid, format, src, &n)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -693,11 +689,7 @@ func (c Int4Codec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16
|
|||||||
}
|
}
|
||||||
|
|
||||||
var n int64
|
var n int64
|
||||||
scanPlan := c.PlanScan(ci, oid, format, &n, true)
|
err := codecScan(c, ci, oid, format, src, &n)
|
||||||
if scanPlan == nil {
|
|
||||||
return nil, fmt.Errorf("PlanScan did not find a plan")
|
|
||||||
}
|
|
||||||
err := scanPlan.Scan(ci, oid, format, src, &n)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1188,11 +1180,7 @@ func (c Int8Codec) DecodeDatabaseSQLValue(ci *ConnInfo, oid uint32, format int16
|
|||||||
}
|
}
|
||||||
|
|
||||||
var n int64
|
var n int64
|
||||||
scanPlan := c.PlanScan(ci, oid, format, &n, true)
|
err := codecScan(c, ci, oid, format, src, &n)
|
||||||
if scanPlan == nil {
|
|
||||||
return nil, fmt.Errorf("PlanScan did not find a plan")
|
|
||||||
}
|
|
||||||
err := scanPlan.Scan(ci, oid, format, src, &n)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-5
@@ -210,11 +210,7 @@ func (c Int<%= pg_byte_size %>Codec) DecodeDatabaseSQLValue(ci *ConnInfo, oid ui
|
|||||||
}
|
}
|
||||||
|
|
||||||
var n int64
|
var n int64
|
||||||
scanPlan := c.PlanScan(ci, oid, format, &n, true)
|
err := codecScan(c, ci, oid, format, src, &n)
|
||||||
if scanPlan == nil {
|
|
||||||
return nil, fmt.Errorf("PlanScan did not find a plan")
|
|
||||||
}
|
|
||||||
err := scanPlan.Scan(ci, oid, format, src, &n)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -968,3 +968,19 @@ func codecScan(codec Codec, ci *ConnInfo, oid uint32, format int16, src []byte,
|
|||||||
}
|
}
|
||||||
return scanPlan.Scan(ci, oid, format, src, dst)
|
return scanPlan.Scan(ci, oid, format, src, dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func codecDecodeToTextFormat(codec Codec, ci *ConnInfo, oid uint32, format int16, src []byte) (driver.Value, error) {
|
||||||
|
if format == TextFormatCode {
|
||||||
|
return string(src), nil
|
||||||
|
} else {
|
||||||
|
value, err := codec.DecodeValue(ci, oid, format, src)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
buf, err := codec.Encode(ci, oid, TextFormatCode, value, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return string(buf), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user