From 6f398d8bb59696901d4fe3a9c88e158f54b9b395 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 6 May 2017 08:48:40 -0500 Subject: [PATCH] Update pgproto3 to enable pgmock --- read.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/read.go b/read.go index 7ddad508..033bada4 100644 --- a/read.go +++ b/read.go @@ -1,6 +1,7 @@ package pgio import ( + "bytes" "encoding/binary" ) @@ -38,3 +39,13 @@ 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 +}