Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame^] | 1 | //TODO INCOMPLETE |
| 2 | /* |
| 3 | * @author: ucla-cs |
| 4 | * |
| 5 | * Encodes CCN object into xml tags |
| 6 | */ |
| 7 | var DataUtils = require('./DataUtils').DataUtils; |
| 8 | |
| 9 | var /*DateFormat*/ canonicalWriteDateFormat = null; |
| 10 | var /* DateFormat*/ canonicalReadDateFormat = null; |
| 11 | var /*String*/ PAD_STRING = "000000000"; |
| 12 | var /*int*/ NANO_LENGTH = 9; |
| 13 | |
| 14 | var TextXMLCodec = function TextXMLCodec(){ |
| 15 | |
| 16 | this.CCN_NAMESPACE = "http://www.parc.com/ccn"; // String |
| 17 | this.CCN_PREFIX = "ccn"; // String |
| 18 | this.CODEC_NAME = "Text";// String |
| 19 | this.BINARY_ATTRIBUTE = "ccnbencoding";// String |
| 20 | this.BINARY_ATTRIBUTE_VALUE = "base64Binary";// String |
| 21 | |
| 22 | |
| 23 | }; |
| 24 | |
| 25 | //returns a string |
| 26 | |
| 27 | TextXMLCodec.protpotype.codecName = function() { return this.CODEC_NAME; } ; |
| 28 | |
| 29 | //returns a string |
| 30 | TextXMLCodec.protottype.encodeBinaryElement = function(/*byte []*/ element) { |
| 31 | if ((null == element) || (0 == element.length)) |
| 32 | return new String(""); |
| 33 | return new String(DataUtils.base64Encode(element)); |
| 34 | }; |
| 35 | |
| 36 | /* returns a string */ |
| 37 | TextXMLCodec.prototype.encodeBinaryElement = function(/*byte []*/ element, /*int*/ offset, /*int*/ length) { |
| 38 | if ((null == element) || (0 == element.length)) |
| 39 | return new String(""); |
| 40 | ByteBuffer bbuf = ByteBuffer.wrap(element, offset, length); |
| 41 | return new String(DataUtils.base64Encode(bbuf.array())); |
| 42 | }; |
| 43 | |
| 44 | /*returns a byte array*/ |
| 45 | TextXMLCodec.prototype.decodeBinaryElement = function(/*String*/ element) { |
| 46 | if ((null == element) || (0 == element.length())) |
| 47 | return new byte[0]; |
| 48 | return DataUtils.base64Decode(element.getBytes()); |
| 49 | }; |
| 50 | |
| 51 | |
| 52 | /* |
| 53 | Decode Data |
| 54 | */ |
| 55 | |
| 56 | |
| 57 | /* |
| 58 | Encode Date |
| 59 | */ |