瀏覽代碼

codec: cbor: handle RAW []byte in EncodeStringBytes, and some minor changes.

- misc: spelling correction: correct Selver to Selfer
- update tests for cleaner (single-line) output using printf
Ugorji Nwoke 10 年之前
父節點
當前提交
bc08fcb1b9
共有 3 個文件被更改,包括 17 次插入12 次删除
  1. 5 1
      codec/cbor.go
  2. 4 4
      codec/gen.go
  3. 8 7
      codec/tests.sh

+ 5 - 1
codec/cbor.go

@@ -158,7 +158,11 @@ func (e *cborEncDriver) EncodeSymbol(v string) {
 }
 
 func (e *cborEncDriver) EncodeStringBytes(c charEncoding, v []byte) {
-	e.encLen(cborBaseBytes, len(v))
+	if c == c_RAW {
+		e.encLen(cborBaseBytes, len(v))
+	} else {
+		e.encLen(cborBaseString, len(v))
+	}
 	e.w.writeb(v)
 }
 

+ 4 - 4
codec/gen.go

@@ -219,8 +219,8 @@ func Gen(w io.Writer, buildTags, pkgName, uid string, useUnsafe bool, typ ...ref
 	x.line("const (")
 	x.linef("codecSelferC_UTF8%s = %v", x.xs, int64(c_UTF8))
 	x.linef("codecSelferC_RAW%s = %v", x.xs, int64(c_RAW))
-	x.linef("codecSelverValueTypeArray%s = %v", x.xs, int64(valueTypeArray))
-	x.linef("codecSelverValueTypeMap%s = %v", x.xs, int64(valueTypeMap))
+	x.linef("codecSelferValueTypeArray%s = %v", x.xs, int64(valueTypeArray))
+	x.linef("codecSelferValueTypeMap%s = %v", x.xs, int64(valueTypeMap))
 	x.line(")")
 	x.line("var (")
 	x.line("codecSelferBitsize" + x.xs + " = uint8(reflect.TypeOf(uint(0)).Bits())")
@@ -1453,7 +1453,7 @@ func (x *genRunner) decStruct(varname string, rtid uintptr, t reflect.Type) {
 	// if container is map
 	// x.line("if z.DecContainerIsMap() { ")
 	i := x.varsfx()
-	x.line("if r.IsContainerType(codecSelverValueTypeMap" + x.xs + ") {")
+	x.line("if r.IsContainerType(codecSelferValueTypeMap" + x.xs + ") {")
 	x.line(genTempVarPfx + "l" + i + " := r.ReadMapStart()")
 	x.linef("if %sl%s == 0 {", genTempVarPfx, i)
 	x.line("r.ReadEnd()")
@@ -1470,7 +1470,7 @@ func (x *genRunner) decStruct(varname string, rtid uintptr, t reflect.Type) {
 
 	// else if container is array
 	// x.line("} else if z.DecContainerIsArray() { ")
-	x.line("} else if r.IsContainerType(codecSelverValueTypeArray" + x.xs + ") {")
+	x.line("} else if r.IsContainerType(codecSelferValueTypeArray" + x.xs + ") {")
 	x.line(genTempVarPfx + "l" + i + " := r.ReadArrayStart()")
 	x.linef("if %sl%s == 0 {", genTempVarPfx, i)
 	x.line("r.ReadEnd()")

+ 8 - 7
codec/tests.sh

@@ -24,17 +24,18 @@ _run() {
         esac
     done
     # shift $((OPTIND-1))
-    echo ">>>>>>> tags: $ztags"
+    printf '............. TAGS: %s .............\n' "$ztags"
+    # echo ">>>>>>> TAGS: $ztags"
     
     OPTIND=1
     while getopts "xurtcinsvg" flag
     do
         case "x$flag" in 
-            'xt') echo ">>>>>>> REGULAR    "; go test "-tags=$ztags" "$zverbose" ; sleep 2 ;;
-            'xc') echo ">>>>>>> CANONICAL  "; go test "-tags=$ztags" "$zverbose" -tc; sleep 2 ;;
-            'xi') echo ">>>>>>> I/O        "; go test "-tags=$ztags" "$zverbose" -ti; sleep 2 ;;
-            'xn') echo ">>>>>>> NO_SYMBOLS "; go test "-tags=$ztags" "$zverbose" -tn; sleep 2 ;;
-            'xs') echo ">>>>>>> TO_ARRAY   "; go test "-tags=$ztags" "$zverbose" -ts; sleep 2 ;;
+            'xt') printf ">>>>>>> REGULAR    : "; go test "-tags=$ztags" "$zverbose" ; sleep 2 ;;
+            'xc') printf ">>>>>>> CANONICAL  : "; go test "-tags=$ztags" "$zverbose" -tc; sleep 2 ;;
+            'xi') printf ">>>>>>> I/O        : "; go test "-tags=$ztags" "$zverbose" -ti; sleep 2 ;;
+            'xn') printf ">>>>>>> NO_SYMBOLS : "; go test "-tags=$ztags" "$zverbose" -tn; sleep 2 ;;
+            'xs') printf ">>>>>>> TO_ARRAY   : "; go test "-tags=$ztags" "$zverbose" -ts; sleep 2 ;;
             *) ;;
         esac
     done
@@ -43,7 +44,7 @@ _run() {
     OPTIND=1
 }
 
-echo ">>>>>>> RUNNING VARIATIONS OF TESTS"    
+# echo ">>>>>>> RUNNING VARIATIONS OF TESTS"    
 if [[ "x$@" = x ]]; then
     # r, x, g, gu
     _run "-rtcins"