mirror of https://github.com/jackc/pgx.git
Added binary encoding to int4 and int8
parent
85ffca4fe0
commit
31a9683cc1
|
@ -36,7 +36,8 @@ func init() {
|
||||||
valueTranscoders[oid(20)] = &valueTranscoder{
|
valueTranscoders[oid(20)] = &valueTranscoder{
|
||||||
DecodeText: decodeInt8FromText,
|
DecodeText: decodeInt8FromText,
|
||||||
DecodeBinary: decodeInt8FromBinary,
|
DecodeBinary: decodeInt8FromBinary,
|
||||||
EncodeTo: encodeInt8}
|
EncodeTo: encodeInt8,
|
||||||
|
EncodeFormat: 1}
|
||||||
|
|
||||||
// int2
|
// int2
|
||||||
valueTranscoders[oid(21)] = &valueTranscoder{
|
valueTranscoders[oid(21)] = &valueTranscoder{
|
||||||
|
@ -47,7 +48,8 @@ func init() {
|
||||||
valueTranscoders[oid(23)] = &valueTranscoder{
|
valueTranscoders[oid(23)] = &valueTranscoder{
|
||||||
DecodeText: decodeInt4FromText,
|
DecodeText: decodeInt4FromText,
|
||||||
DecodeBinary: decodeInt4FromBinary,
|
DecodeBinary: decodeInt4FromBinary,
|
||||||
EncodeTo: encodeInt4}
|
EncodeTo: encodeInt4,
|
||||||
|
EncodeFormat: 1}
|
||||||
|
|
||||||
// text
|
// text
|
||||||
valueTranscoders[oid(25)] = &valueTranscoder{
|
valueTranscoders[oid(25)] = &valueTranscoder{
|
||||||
|
@ -108,9 +110,8 @@ func decodeInt8FromBinary(mr *MessageReader, size int32) interface{} {
|
||||||
|
|
||||||
func encodeInt8(buf *bytes.Buffer, value interface{}) {
|
func encodeInt8(buf *bytes.Buffer, value interface{}) {
|
||||||
v := value.(int64)
|
v := value.(int64)
|
||||||
s := strconv.FormatInt(int64(v), 10)
|
binary.Write(buf, binary.BigEndian, int32(8))
|
||||||
binary.Write(buf, binary.BigEndian, int32(len(s)))
|
binary.Write(buf, binary.BigEndian, v)
|
||||||
buf.WriteString(s)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeInt2FromText(mr *MessageReader, size int32) interface{} {
|
func decodeInt2FromText(mr *MessageReader, size int32) interface{} {
|
||||||
|
@ -147,9 +148,8 @@ func decodeInt4FromBinary(mr *MessageReader, size int32) interface{} {
|
||||||
|
|
||||||
func encodeInt4(buf *bytes.Buffer, value interface{}) {
|
func encodeInt4(buf *bytes.Buffer, value interface{}) {
|
||||||
v := value.(int32)
|
v := value.(int32)
|
||||||
s := strconv.FormatInt(int64(v), 10)
|
binary.Write(buf, binary.BigEndian, int32(4))
|
||||||
binary.Write(buf, binary.BigEndian, int32(len(s)))
|
binary.Write(buf, binary.BigEndian, v)
|
||||||
buf.WriteString(s)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeFloat4FromText(mr *MessageReader, size int32) interface{} {
|
func decodeFloat4FromText(mr *MessageReader, size int32) interface{} {
|
||||||
|
|
Loading…
Reference in New Issue