瀏覽代碼

codec: readn/writen handle up to 7 bytes at a time now

This allows writing "false" within json
Ugorji Nwoke 6 年之前
父節點
當前提交
e04c642f55
共有 2 個文件被更改,包括 12 次插入11 次删除
  1. 7 6
      codec/reader.go
  2. 5 5
      codec/writer.go

+ 7 - 6
codec/reader.go

@@ -15,7 +15,8 @@ type decReader interface {
 	readx(n uint) []byte
 	readb([]byte)
 	readn1() uint8
-	readn(num uint8) (v [6]byte)
+	// read up to 7 bytes at a time
+	readn(num uint8) (v [7]byte)
 	numread() uint // number of bytes read
 	track()
 	stopTrack() []byte
@@ -191,7 +192,7 @@ func (z *ioDecReader) UnreadByte() (err error) {
 	return
 }
 
-func (z *ioDecReader) readn(num uint8) (bs [6]byte) {
+func (z *ioDecReader) readn(num uint8) (bs [7]byte) {
 	z.readb(bs[:num])
 	// copy(bs[:], z.readx(uint(num)))
 	return
@@ -467,7 +468,7 @@ func (z *bufioDecReader) unreadn1() {
 	}
 }
 
-func (z *bufioDecReader) readn(num uint8) (bs [6]byte) {
+func (z *bufioDecReader) readn(num uint8) (bs [7]byte) {
 	z.readb(bs[:num])
 	// copy(bs[:], z.readx(uint(num)))
 	return
@@ -837,7 +838,7 @@ func (z *bytesDecReader) readn1() (v uint8) {
 	return
 }
 
-func (z *bytesDecReader) readn(num uint8) (bs [6]byte) {
+func (z *bytesDecReader) readn(num uint8) (bs [7]byte) {
 	// if z.c+2 >= uint(len(z.b)) {
 	// 	panic(io.EOF)
 	// }
@@ -1200,13 +1201,13 @@ func (z *decRd) unreadn1() {
 	}
 }
 
-func (z *decRd) readn(num uint8) [6]byte {
+func (z *decRd) readn(num uint8) [7]byte {
 	if z.bytes {
 		return z.rb.readn(num)
 	}
 	return z.readnIO(num)
 }
-func (z *decRd) readnIO(num uint8) [6]byte {
+func (z *decRd) readnIO(num uint8) [7]byte {
 	if z.bufio {
 		return z.bi.readn(num)
 	}

+ 5 - 5
codec/writer.go

@@ -12,8 +12,8 @@ type encWriter interface {
 	writeqstr(string) // write string wrapped in quotes ie "..."
 	writen1(byte)
 	writen2(byte, byte)
-	// writen will write up to 6 bytes at a time.
-	writen(b [6]byte, num uint8)
+	// writen will write up to 7 bytes at a time.
+	writen(b [7]byte, num uint8)
 	end()
 }
 
@@ -275,7 +275,7 @@ func (z *bufioEncWriter) writen2(b1, b2 byte) {
 	z.n += 2
 }
 
-func (z *bufioEncWriter) writen(b [6]byte, num uint8) {
+func (z *bufioEncWriter) writen(b [7]byte, num uint8) {
 	if int(num) > len(z.buf)-z.n {
 		z.flush()
 	}
@@ -324,7 +324,7 @@ func (z *bytesEncAppender) writen2(b1, b2 byte) {
 	// z.b = append(z.b, []byte{b1, b2}...) // cost: 83
 	// z.b = append(append(z.b, b1), b2) // cost 82
 }
-func (z *bytesEncAppender) writen(s [6]byte, num uint8) {
+func (z *bytesEncAppender) writen(s [7]byte, num uint8) {
 	z.b = append(z.b, s[:num]...)
 }
 func (z *bytesEncAppender) endErr() error {
@@ -393,7 +393,7 @@ func (z *encWr) writen2(b1, b2 byte) {
 		z.wf.writen2(b1, b2)
 	}
 }
-func (z *encWr) writen(b [6]byte, num uint8) {
+func (z *encWr) writen(b [7]byte, num uint8) {
 	if z.bytes {
 		z.wb.writen(b, num)
 	} else {