Changeset 652
- Timestamp:
- Mar 30, 2007, 2:23:39 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tcl/src/RpEncodeTclInterface.cc
r650 r652 162 162 * 163 163 * Full function call: 164 * ::Rappture::encoding::encode ?-as z|b64 ? <string>164 * ::Rappture::encoding::encode ?-as z|b64|zb64? <string> 165 165 */ 166 166 … … 194 194 Tcl_AppendResult(interp, 195 195 "wrong # args: should be \"", cmdName, 196 " ?-as z|b64 ? <string>\"", (char*)NULL);196 " ?-as z|b64|zb64? <string>\"", (char*)NULL); 197 197 return TCL_ERROR; 198 198 } … … 210 210 (strncmp(encodeType,"z",typeLen) == 0) ) { 211 211 compress = 1; 212 base64 = 1;212 base64 = 0; 213 213 } 214 214 else if ( (typeLen == 3) && 215 215 (strncmp(encodeType,"b64",typeLen) == 0) ) { 216 216 compress = 0; 217 base64 = 1; 218 } 219 else if ( (typeLen == 4) && 220 (strncmp(encodeType,"zb64",typeLen) == 0) ) { 221 compress = 1; 217 222 base64 = 1; 218 223 } … … 224 229 } 225 230 Tcl_AppendResult(interp, 226 "\": should be one of z, b64 ",231 "\": should be one of z, b64, zb64", 227 232 (char*)NULL); 228 233 return TCL_ERROR; … … 241 246 Tcl_AppendResult(interp, 242 247 "wrong # args: should be \"", cmdName, 243 " ?-as z|b64 ? <string>\"", (char*)NULL);248 " ?-as z|b64|zb64? <string>\"", (char*)NULL); 244 249 return TCL_ERROR; 245 250 } 246 251 247 252 option = Tcl_GetStringFromObj(objv[nextarg++], &optionLen); 248 buf = Rappture::Buffer(option,optionLen); 253 254 if (strncmp(option,"@@RP-ENC:z\n",11) == 0) { 255 buf = Rappture::Buffer(option+11,optionLen-11); 256 buf.decode(1,0); 257 } 258 else if (strncmp(option,"@@RP-ENC:b64\n",13) == 0) { 259 buf = Rappture::Buffer(option+13,optionLen-13); 260 buf.decode(0,1); 261 } 262 else if (strncmp(option,"@@RP-ENC:zb64\n",14) == 0) { 263 buf = Rappture::Buffer(option+14,optionLen-14); 264 buf.decode(1,1); 265 } 266 else { 267 // no special recognized tags 268 buf = Rappture::Buffer(option,optionLen); 269 } 249 270 250 271 buf.encode(compress,base64); 251 272 result = Tcl_GetObjResult(interp); 273 274 if ((compress == 1) && (base64 == 0)) { 275 Tcl_AppendToObj(result,"@@RP-ENC:z\n",11); 276 } 277 else if ((compress == 0) && (base64 == 1)) { 278 Tcl_AppendToObj(result,"@@RP-ENC:b64\n",13); 279 } 280 else if ((compress == 1) && (base64 == 1)) { 281 Tcl_AppendToObj(result,"@@RP-ENC:zb64\n",14); 282 } 283 else { 284 // do nothing 285 } 286 252 287 Tcl_AppendToObj(result,buf.bytes(),buf.size()); 253 288 … … 264 299 * 265 300 * Full function call: 266 * ::Rappture::encoding::decode ?-as z|b64 ? <string>301 * ::Rappture::encoding::decode ?-as z|b64|zb64? <string> 267 302 */ 268 303 … … 296 331 Tcl_AppendResult(interp, 297 332 "wrong # args: should be \"", cmdName, 298 " ?-as z|b64 ? <string>\"", (char*)NULL);333 " ?-as z|b64|zb64? <string>\"", (char*)NULL); 299 334 return TCL_ERROR; 300 335 } … … 312 347 (strncmp(encodeType,"z",typeLen) == 0) ) { 313 348 decompress = 1; 314 base64 = 1;349 base64 = 0; 315 350 } 316 351 else if ( (typeLen == 3) && 317 352 (strncmp(encodeType,"b64",typeLen) == 0) ) { 318 353 decompress = 0; 354 base64 = 1; 355 } 356 else if ( (typeLen == 4) && 357 (strncmp(encodeType,"zb64",typeLen) == 0) ) { 358 decompress = 1; 319 359 base64 = 1; 320 360 } … … 326 366 } 327 367 Tcl_AppendResult(interp, 328 "\": should be one of z, b64 ",368 "\": should be one of z, b64, zb64", 329 369 (char*)NULL); 330 370 return TCL_ERROR; … … 343 383 Tcl_AppendResult(interp, 344 384 "wrong # args: should be \"", cmdName, 345 " ?-as z|b64 ? <string>\"", (char*)NULL);385 " ?-as z|b64|zb64? <string>\"", (char*)NULL); 346 386 return TCL_ERROR; 347 387 } 348 388 349 389 option = Tcl_GetStringFromObj(objv[nextarg++], &optionLen); 350 if (encodeType == NULL) { 351 if (strncmp(option,"H4sI",4) == 0) { 352 decompress = 1; 353 base64 = 1; 354 } 355 else { 356 // user did not specify how to treat data 357 // and we cannot guess based on the header. 358 // return data 359 Tcl_AppendResult(interp,option,(char*)NULL); 360 return TCL_OK; 361 } 362 } 363 364 buf = Rappture::Buffer(option,optionLen); 365 buf.decode(decompress,base64); 366 390 391 if (strncmp(option,"@@RP-ENC:z\n",11) == 0) { 392 buf = Rappture::Buffer(option+11,optionLen-11); 393 buf.decode(1,0); 394 } 395 else if (strncmp(option,"@@RP-ENC:b64\n",13) == 0) { 396 buf = Rappture::Buffer(option+13,optionLen-13); 397 buf.decode(0,1); 398 } 399 else if (strncmp(option,"@@RP-ENC:zb64\n",14) == 0) { 400 buf = Rappture::Buffer(option+14,optionLen-14); 401 buf.decode(1,1); 402 } 403 else { 404 // no special recognized tags 405 buf = Rappture::Buffer(option,optionLen); 406 buf.decode(decompress,base64); 407 } 408 409 // buf.decode(decompress,base64); 367 410 result = Tcl_GetObjResult(interp); 411 412 /* 413 if ((decompress == 1) && (base64 == 0)) { 414 Tcl_AppendToObj(result,"@@RP-ENC:z\n",11); 415 buf.encode(0,1); 416 } 417 else if ((decompress == 0) && (base64 == 1)) { 418 Tcl_AppendToObj(result,"@@RP-ENC:b64\n",13); 419 } 420 else if ((decompress == 1) && (base64 == 1)) { 421 Tcl_AppendToObj(result,"@@RP-ENC:zb64\n",14); 422 } 423 else { 424 // do nothing 425 } 426 */ 427 368 428 Tcl_AppendToObj(result,buf.bytes(),buf.size()); 369 429 -
trunk/src/tcl/tests/encode.test
r649 r652 61 61 test encode-2.0.0 {Rappture::encoding::encode, 0 arguments} { 62 62 list [catch {Rappture::encoding::encode} msg] $msg 63 } {1 {wrong # args: should be "Rappture::encoding::encode ?-as z|b64 ? <string>"}}63 } {1 {wrong # args: should be "Rappture::encoding::encode ?-as z|b64|zb64? <string>"}} 64 64 65 65 test encode-2.1.0 {Rappture::encoding::encode, ascii string argument} { 66 66 list [catch {Rappture::encoding::encode "hi"} msg] $msg 67 } {0 {H4sIAAAAAAAAA8vIBACsKpPYAgAAAA== 67 } {0 {@@RP-ENC:zb64 68 H4sIAAAAAAAAA8vIBACsKpPYAgAAAA== 68 69 }} 69 70 … … 72 73 set b [Rappture::encoding::decode -as b64 $h] 73 74 list [catch {Rappture::encoding::encode $b} msg] $msg 74 } {0 {H4sIAAAAAAAAA5Pv5mAAA+bTJ1gY1mhNvsEE5AAAFVLsvBYAAAA= 75 } {0 {@@RP-ENC:zb64 76 H4sIAAAAAAAAA5Pv5mAAA+bTJ1gY1mhNvsEE5AAAFVLsvBYAAAA= 75 77 }} 76 78 77 79 test encode-2.2.0 {Rappture::encoding::encode, -as flag blank value} { 78 80 list [catch {Rappture::encoding::encode -as} msg] $msg 79 } {1 {bad value "": should be one of z, b64 }}81 } {1 {bad value "": should be one of z, b64, zb64}} 80 82 81 83 test encode-2.2.1 {Rappture::encoding::encode, -as flag bad value } { 82 84 list [catch {Rappture::encoding::encode -as zz} msg] $msg 83 } {1 {bad value "zz": should be one of z, b64 }}85 } {1 {bad value "zz": should be one of z, b64, zb64}} 84 86 85 87 test encode-2.2.2 {Rappture::encoding::encode, -as flag correct value z} { 86 88 list [catch {Rappture::encoding::encode -as z} msg] $msg 87 } {1 {wrong # args: should be "Rappture::encoding::encode ?-as z|b64 ? <string>"}}89 } {1 {wrong # args: should be "Rappture::encoding::encode ?-as z|b64|zb64? <string>"}} 88 90 89 91 test encode-2.2.3 {Rappture::encoding::encode, -as z w/ string} { 90 92 list [catch {Rappture::encoding::encode -as z "hi"} msg] $msg 91 } {0 { H4sIAAAAAAAAA8vIBACsKpPYAgAAAA==92 }}93 } {0 {@@RP-ENC:z 94 \xCB\xC8\x3F\x2A\x3F\xD8}} 93 95 94 96 test encode-2.2.4 {Rappture::encoding::encode, -as b64 w/ string} { 95 97 list [catch {Rappture::encoding::encode -as b64 "hi"} msg] $msg 96 } {0 {aGk= 98 } {0 {@@RP-ENC:b64 99 aGk= 97 100 }} 98 101 … … 105 108 test decode-3.0.0 {Rappture::encoding::decode, 0 arguments} { 106 109 list [catch {Rappture::encoding::decode} msg] $msg 107 } {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64 ? <string>"}}110 } {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64|zb64? <string>"}} 108 111 109 112 test decode-3.1.0 {Rappture::encoding::decode, 1 arg, b64 encoded} { … … 112 115 } {0 aGk=} 113 116 114 test decode-3.1.1 {Rappture::encoding::decode, 1 arg, z encoded} {115 set h " H4sIAAAAAAAAA8vIBACsKpPYAgAAAA=="117 test decode-3.1.1 {Rappture::encoding::decode, 1 arg, zb64 encoded} { 118 set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" 116 119 list [catch {Rappture::encoding::decode $h} msg] $msg 117 120 } {0 hi} … … 119 122 test decode-3.1.2 {Rappture::encoding::decode, 2 args} { 120 123 list [catch {Rappture::encoding::decode "hi" "bye"} msg] $msg 121 } {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64 ? <string>"}}124 } {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64|zb64? <string>"}} 122 125 123 126 test decode-3.2.0 {Rappture::encoding::decode, -as flag, no value} { 124 127 list [catch {Rappture::encoding::decode -as} msg] $msg 125 } {1 {bad value "": should be one of z, b64 }}128 } {1 {bad value "": should be one of z, b64, zb64}} 126 129 127 130 test decode-3.2.1 {Rappture::encoding::decode, -as flag, bad value} { 128 131 list [catch {Rappture::encoding::decode -as zz} msg] $msg 129 } {1 {bad value "zz": should be one of z, b64 }}132 } {1 {bad value "zz": should be one of z, b64, zb64}} 130 133 131 test decode-3.2.2 {Rappture::encoding::decode, -as flag, z w/ string} {132 set h " H4sIAAAAAAAAA8vIBACsKpPYAgAAAA=="134 test decode-3.2.2 {Rappture::encoding::decode, -as flag, zb64 w/ string} { 135 set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" 133 136 list [catch {Rappture::encoding::decode -as z $h} msg] $msg 134 137 } {0 hi} 135 138 136 139 test decode-3.2.3 {Rappture::encoding::decode, -as flag, b64 w/ string} { 137 set h " aGk="140 set h "@@RP-ENC:b64\naGk=" 138 141 list [catch {Rappture::encoding::decode -as b64 $h} msg] $msg 139 142 } {0 hi} -
trunk/src2/core/RpBuffer.cc
r621 r652 627 627 SimpleBuffer bout; 628 628 629 if ((base64 == 0) && (compress == 0)) { 630 return err; 631 } 632 629 633 err.addContext("Rappture::Buffer::encode()"); 630 631 634 rewind(); 632 635 … … 664 667 SimpleBuffer bout; 665 668 669 if ((base64 == 0) && (decompress == 0)) { 670 return err; 671 } 672 673 err.addContext("Rappture::Buffer::decode()"); 666 674 rewind(); 667 675
Note: See TracChangeset
for help on using the changeset viewer.