pax_global_header00006660000000000000000000000064134477206460014527gustar00rootroot0000000000000052 comment=8d9c2a3dafd92d070bd758a165022fd1059e3195 pgio-1.0.0/000077500000000000000000000000001344772064600124635ustar00rootroot00000000000000pgio-1.0.0/.travis.yml000066400000000000000000000001131344772064600145670ustar00rootroot00000000000000language: go go: - 1.x - tip matrix: allow_failures: - go: tip pgio-1.0.0/LICENSE000066400000000000000000000020611344772064600134670ustar00rootroot00000000000000Copyright (c) 2019 Jack Christensen MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pgio-1.0.0/README.md000066400000000000000000000007051344772064600137440ustar00rootroot00000000000000[![](https://godoc.org/github.com/jackc/pgio?status.svg)](https://godoc.org/github.com/jackc/pgio) [![Build Status](https://travis-ci.org/jackc/pgio.svg)](https://travis-ci.org/jackc/pgio) # pgio Package pgio is a low-level toolkit building messages in the PostgreSQL wire protocol. pgio provides functions for appending integers to a []byte while doing byte order conversion. Extracted from original implementation in https://github.com/jackc/pgx. pgio-1.0.0/doc.go000066400000000000000000000003131344772064600135540ustar00rootroot00000000000000// Package pgio is a low-level toolkit building messages in the PostgreSQL wire protocol. /* pgio provides functions for appending integers to a []byte while doing byte order conversion. */ package pgio pgio-1.0.0/go.mod000066400000000000000000000000461344772064600135710ustar00rootroot00000000000000module github.com/jackc/pgio go 1.12 pgio-1.0.0/write.go000066400000000000000000000015161344772064600141470ustar00rootroot00000000000000package pgio import "encoding/binary" func AppendUint16(buf []byte, n uint16) []byte { wp := len(buf) buf = append(buf, 0, 0) binary.BigEndian.PutUint16(buf[wp:], n) return buf } func AppendUint32(buf []byte, n uint32) []byte { wp := len(buf) buf = append(buf, 0, 0, 0, 0) binary.BigEndian.PutUint32(buf[wp:], n) return buf } func AppendUint64(buf []byte, n uint64) []byte { wp := len(buf) buf = append(buf, 0, 0, 0, 0, 0, 0, 0, 0) binary.BigEndian.PutUint64(buf[wp:], n) return buf } func AppendInt16(buf []byte, n int16) []byte { return AppendUint16(buf, uint16(n)) } func AppendInt32(buf []byte, n int32) []byte { return AppendUint32(buf, uint32(n)) } func AppendInt64(buf []byte, n int64) []byte { return AppendUint64(buf, uint64(n)) } func SetInt32(buf []byte, n int32) { binary.BigEndian.PutUint32(buf, uint32(n)) } pgio-1.0.0/write_test.go000066400000000000000000000041511344772064600152040ustar00rootroot00000000000000package pgio import ( "reflect" "testing" ) func TestAppendUint16NilBuf(t *testing.T) { buf := AppendUint16(nil, 1) if !reflect.DeepEqual(buf, []byte{0, 1}) { t.Errorf("AppendUint16(nil, 1) => %v, want %v", buf, []byte{0, 1}) } } func TestAppendUint16EmptyBuf(t *testing.T) { buf := []byte{} buf = AppendUint16(buf, 1) if !reflect.DeepEqual(buf, []byte{0, 1}) { t.Errorf("AppendUint16(nil, 1) => %v, want %v", buf, []byte{0, 1}) } } func TestAppendUint16BufWithCapacityDoesNotAllocate(t *testing.T) { buf := make([]byte, 0, 4) AppendUint16(buf, 1) buf = buf[0:2] if !reflect.DeepEqual(buf, []byte{0, 1}) { t.Errorf("AppendUint16(nil, 1) => %v, want %v", buf, []byte{0, 1}) } } func TestAppendUint32NilBuf(t *testing.T) { buf := AppendUint32(nil, 1) if !reflect.DeepEqual(buf, []byte{0, 0, 0, 1}) { t.Errorf("AppendUint32(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 1}) } } func TestAppendUint32EmptyBuf(t *testing.T) { buf := []byte{} buf = AppendUint32(buf, 1) if !reflect.DeepEqual(buf, []byte{0, 0, 0, 1}) { t.Errorf("AppendUint32(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 1}) } } func TestAppendUint32BufWithCapacityDoesNotAllocate(t *testing.T) { buf := make([]byte, 0, 4) AppendUint32(buf, 1) buf = buf[0:4] if !reflect.DeepEqual(buf, []byte{0, 0, 0, 1}) { t.Errorf("AppendUint32(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 1}) } } func TestAppendUint64NilBuf(t *testing.T) { buf := AppendUint64(nil, 1) if !reflect.DeepEqual(buf, []byte{0, 0, 0, 0, 0, 0, 0, 1}) { t.Errorf("AppendUint64(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 0, 0, 0, 0, 1}) } } func TestAppendUint64EmptyBuf(t *testing.T) { buf := []byte{} buf = AppendUint64(buf, 1) if !reflect.DeepEqual(buf, []byte{0, 0, 0, 0, 0, 0, 0, 1}) { t.Errorf("AppendUint64(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 0, 0, 0, 0, 1}) } } func TestAppendUint64BufWithCapacityDoesNotAllocate(t *testing.T) { buf := make([]byte, 0, 8) AppendUint64(buf, 1) buf = buf[0:8] if !reflect.DeepEqual(buf, []byte{0, 0, 0, 0, 0, 0, 0, 1}) { t.Errorf("AppendUint64(nil, 1) => %v, want %v", buf, []byte{0, 0, 0, 0, 0, 0, 0, 1}) } }