mirror of https://github.com/jackc/pgx.git
Remove read functions from pgio and update docs
parent
b1489a1eab
commit
0cda099bb5
|
@ -1,8 +1,6 @@
|
|||
// Package pgio a extremely low-level IO toolkit for the PostgreSQL wire protocol.
|
||||
// Package pgio is a low-level toolkit building messages in the PostgreSQL wire protocol.
|
||||
/*
|
||||
pgio provides functions for reading and writing integers from io.Reader and
|
||||
io.Writer while doing byte order conversion. It publishes interfaces which
|
||||
readers and writers may implement to decode and encode messages with the minimum
|
||||
of memory allocations.
|
||||
pgio provides functions for appending integers to a []byte while doing byte
|
||||
order conversion.
|
||||
*/
|
||||
package pgio
|
||||
|
|
51
pgio/read.go
51
pgio/read.go
|
@ -1,51 +0,0 @@
|
|||
package pgio
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
func NextByte(buf []byte) ([]byte, byte) {
|
||||
b := buf[0]
|
||||
return buf[1:], b
|
||||
}
|
||||
|
||||
func NextUint16(buf []byte) ([]byte, uint16) {
|
||||
n := binary.BigEndian.Uint16(buf)
|
||||
return buf[2:], n
|
||||
}
|
||||
|
||||
func NextUint32(buf []byte) ([]byte, uint32) {
|
||||
n := binary.BigEndian.Uint32(buf)
|
||||
return buf[4:], n
|
||||
}
|
||||
|
||||
func NextUint64(buf []byte) ([]byte, uint64) {
|
||||
n := binary.BigEndian.Uint64(buf)
|
||||
return buf[8:], n
|
||||
}
|
||||
|
||||
func NextInt16(buf []byte) ([]byte, int16) {
|
||||
buf, n := NextUint16(buf)
|
||||
return buf, int16(n)
|
||||
}
|
||||
|
||||
func NextInt32(buf []byte) ([]byte, int32) {
|
||||
buf, n := NextUint32(buf)
|
||||
return buf, int32(n)
|
||||
}
|
||||
|
||||
func NextInt64(buf []byte) ([]byte, int64) {
|
||||
buf, n := NextUint64(buf)
|
||||
return buf, int64(n)
|
||||
}
|
||||
|
||||
func NextCString(buf []byte) ([]byte, string, bool) {
|
||||
idx := bytes.IndexByte(buf, 0)
|
||||
if idx < 0 {
|
||||
return buf, "", false
|
||||
}
|
||||
cstring := string(buf[:idx])
|
||||
buf = buf[:idx+1]
|
||||
return buf, cstring, true
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package pgio
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNextByte(t *testing.T) {
|
||||
buf := []byte{42, 1}
|
||||
var b byte
|
||||
buf, b = NextByte(buf)
|
||||
if b != 42 {
|
||||
t.Errorf("NextByte(buf) => %v, want %v", b, 42)
|
||||
}
|
||||
buf, b = NextByte(buf)
|
||||
if b != 1 {
|
||||
t.Errorf("NextByte(buf) => %v, want %v", b, 1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextUint16(t *testing.T) {
|
||||
buf := []byte{0, 42, 0, 1}
|
||||
var n uint16
|
||||
buf, n = NextUint16(buf)
|
||||
if n != 42 {
|
||||
t.Errorf("NextUint16(buf) => %v, want %v", n, 42)
|
||||
}
|
||||
buf, n = NextUint16(buf)
|
||||
if n != 1 {
|
||||
t.Errorf("NextUint16(buf) => %v, want %v", n, 1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextUint32(t *testing.T) {
|
||||
buf := []byte{0, 0, 0, 42, 0, 0, 0, 1}
|
||||
var n uint32
|
||||
buf, n = NextUint32(buf)
|
||||
if n != 42 {
|
||||
t.Errorf("NextUint32(buf) => %v, want %v", n, 42)
|
||||
}
|
||||
buf, n = NextUint32(buf)
|
||||
if n != 1 {
|
||||
t.Errorf("NextUint32(buf) => %v, want %v", n, 1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextUint64(t *testing.T) {
|
||||
buf := []byte{0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 1}
|
||||
var n uint64
|
||||
buf, n = NextUint64(buf)
|
||||
if n != 42 {
|
||||
t.Errorf("NextUint64(buf) => %v, want %v", n, 42)
|
||||
}
|
||||
buf, n = NextUint64(buf)
|
||||
if n != 1 {
|
||||
t.Errorf("NextUint64(buf) => %v, want %v", n, 1)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue