first commit
diff --git a/src/encoding/BinaryXMLCodec.js b/src/encoding/BinaryXMLCodec.js
new file mode 100644
index 0000000..077c7e2
--- /dev/null
+++ b/src/encoding/BinaryXMLCodec.js
@@ -0,0 +1,135 @@
+
+var XML_EXT = 0x00;
+
+var XML_TAG = 0x01;
+
+var XML_DTAG = 0x02;
+
+var XML_ATTR = 0x03;
+
+var XML_DATTR = 0x04;
+
+var XML_BLOB = 0x05;
+
+var XML_UDATA = 0x06;
+
+var XML_CLOSE = 0x0;
+
+var XML_SUBTYPE_PROCESSING_INSTRUCTIONS = 16;
+
+
+var XML_TT_BITS = 3;
+var XML_TT_MASK = ((1 << XML_TT_BITS) - 1);
+var XML_TT_VAL_BITS = XML_TT_BITS + 1;
+var XML_TT_VAL_MASK = ((1 << (XML_TT_VAL_BITS)) - 1);
+var XML_REG_VAL_BITS = 7;
+var XML_REG_VAL_MASK = ((1 << XML_REG_VAL_BITS) - 1);
+var XML_TT_NO_MORE = (1 << XML_REG_VAL_BITS); // 0x80
+var BYTE_MASK = 0xFF;
+var LONG_BYTES = 8;
+var LONG_BITS = 64;
+
+var bits_11 = 0x0000007FFL;
+var bits_18 = 0x00003FFFFL;
+var bits_32 = 0x0FFFFFFFFL;
+
+
+var TypeAndVal = function TypeAndVal(_type,_val) {
+ this.type = _type;
+ this.val = _val;
+
+};
+exports.TypeAndVal = TypeAndVal;
+
+var BinaryXMLCodec = function BinaryXMLCodec(){
+
+ this.CODEC_NAME = "Binary";
+
+
+
+};
+
+exports.BinaryXMLCodec = BinaryXMLCodec;
+
+
+
+BinaryXMLCodec.prototype.encodeTypeAndVal = function(
+ //int
+ type,
+ //long
+ val,
+ //byte []
+ buf,
+ //int
+ offset) {
+
+ if ((type > XML_UDATA) || (type < 0) || (val < 0)) {
+ throw new Exception("Tag and value must be positive, and tag valid.");
+ }
+
+ // Encode backwards. Calculate how many bytes we need:
+ int numEncodingBytes = numEncodingBytes(val);
+
+ if ((offset + numEncodingBytes) > buf.length) {
+ throw new Exception("Buffer space of " + (buf.length-offset) +
+ " bytes insufficient to hold " +
+ numEncodingBytes + " of encoded type and value.");
+ }
+
+
+ buf[offset + numEncodingBytes - 1] =
+ (BYTE_MASK &
+ (((XML_TT_MASK & type) |
+ ((XML_TT_VAL_MASK & val) << XML_TT_BITS))) |
+ XML_TT_NO_MORE);
+ val = val >>> XML_TT_VAL_BITS;;
+
+ int i = offset + numEncodingBytes - 2;
+ while ((0 != val) && (i >= offset)) {
+ buf[i] = (BYTE_MASK &
+ (val & XML_REG_VAL_MASK));
+ val = val >>> XML_REG_VAL_BITS;
+ --i;
+ }
+
+ return numEncodingBytes;
+};
+
+BinaryXMLCodec.prototype.decodeTypeAndVal = function(
+ /*InputStream*/
+ istream) {
+
+ int next;
+ int type = -1;
+ long val = 0;
+ boolean more = true;
+
+ do {
+ next = istream.read();
+
+ if (next < 0) {
+ return null;
+ }
+
+ if ((0 == next) && (0 == val)) {
+ return null;
+ }
+
+ more = (0 == (next & XML_TT_NO_MORE));
+
+ if (more) {
+ val = val << XML_REG_VAL_BITS;
+ val |= (next & XML_REG_VAL_MASK);
+ } else {
+
+ type = next & XML_TT_MASK;
+ val = val << XML_TT_VAL_BITS;
+ val |= ((next >>> XML_TT_BITS) & XML_TT_VAL_MASK);
+ }
+
+ } while (more);
+
+ return new TypeAndVal(type, val);
+};
+
+//TODO
\ No newline at end of file
diff --git a/src/encoding/BinaryXMLDecoder.js b/src/encoding/BinaryXMLDecoder.js
new file mode 100644
index 0000000..4a8b1c4
--- /dev/null
+++ b/src/encoding/BinaryXMLDecoder.js
@@ -0,0 +1,89 @@
+var MARK_LEN=512;
+var DEBUG_MAX_LEN = 32768;
+
+var BinaryXMLDecoder = new BinaryXMLDecoder(_Istream){
+ this.Istream = _Istream;
+
+};
+
+
+BinaryXMLDecoder.prototype.readStartElement =function(
+ //String
+ startTag,
+ //TreeMap<String, String>
+ attributes) {
+
+ try {
+ BinaryXMLCodec.TypeAndVal tv = BinaryXMLCodec.decodeTypeAndVal(this.Istream);
+
+ if (null == tv) {
+ throw new Exception("Expected start element: " + startTag + " got something not a tag.");
+ }
+
+ String decodedTag = null;
+
+ if (tv.type() == BinaryXMLCodec.XML_TAG) {
+
+ decodedTag = BinaryXMLCodec.decodeUString(this.Istream, tv.val()+1);
+
+ } else if (tv.type() == BinaryXMLCodec.XML_DTAG) {
+ decodedTag = tagToString(tv.val());
+ }
+
+ if ((null == decodedTag) || (!decodedTag.equals(startTag))) {
+ throw new Exception("Expected start element: " + startTag + " got: " + decodedTag + "(" + tv.val() + ")");
+ }
+
+ if (null != attributes) {
+ readAttributes(attributes);
+ }
+
+ } catch (e) {
+ throw new Exception("readStartElement", e);
+ }
+};
+
+BinaryXMLDecoder.prototype.readAttributes = function(
+ //TreeMap<String,String>
+ attributes){
+
+ if (null == attributes) {
+ return;
+ }
+
+ try {
+
+ BinaryXMLCodec.TypeAndVal nextTV = BinaryXMLCodec.peekTypeAndVal(_istream);
+
+ while ((null != nextTV) && ((BinaryXMLCodec.XML_ATTR == nextTV.type()) ||
+ (BinaryXMLCodec.XML_DATTR == nextTV.type()))) {
+
+ BinaryXMLCodec.TypeAndVal thisTV = BinaryXMLCodec.decodeTypeAndVal(this.Istream);
+
+ var attributeName = null;
+ if (BinaryXMLCodec.XML_ATTR == thisTV.type()) {
+
+ attributeName = BinaryXMLCodec.decodeUString(_istream, thisTV.val()+1);
+
+ } else if (BinaryXMLCodec.XML_DATTR == thisTV.type()) {
+ // DKS TODO are attributes same or different dictionary?
+ attributeName = tagToString(thisTV.val());
+ if (null == attributeName) {
+ throw new ContentDecodingException("Unknown DATTR value" + thisTV.val());
+ }
+ }
+
+ var attributeValue = BinaryXMLCodec.decodeUString(_istream);
+
+ attributes.put(attributeName, attributeValue);
+
+ nextTV = BinaryXMLCodec.peekTypeAndVal(_istream);
+ }
+
+ } catch ( e) {
+
+ throw new ContentDecodingException("readStartElement", e);
+ }
+};
+
+//TODO
\ No newline at end of file
diff --git a/src/encoding/BinaryXMLEncoder.js b/src/encoding/BinaryXMLEncoder.js
new file mode 100644
index 0000000..7ccf3b4
--- /dev/null
+++ b/src/encoding/BinaryXMLEncoder.js
@@ -0,0 +1,31 @@
+
+var BinaryXMLEncoder = function BinaryXMLEncoder(){
+
+BinaryXMLEncoder.prototype.writeStartElement = function(
+ //String
+ tag,
+ //TreeMap<String,String>
+ attributes){
+
+}
+ try {
+ var dictionaryVal = stringToTag(tag);
+
+ if (null == dictionaryVal) {
+ BinaryXMLCodec.encodeUString(_ostream, tag, BinaryXMLCodec.XML_TAG);
+
+ } else {
+ BinaryXMLCodec.encodeTypeAndVal(BinaryXMLCodec.XML_DTAG, dictionaryVal, _ostream);
+ }
+
+ if (null != attributes) {
+ writeAttributes(attributes);
+ }
+
+ } catch (e) {
+ throw new Exception(e);
+ }
+};
+
+
+//TODO
\ No newline at end of file
diff --git a/src/encoding/TextXMLCodec.js b/src/encoding/TextXMLCodec.js
new file mode 100644
index 0000000..ea64188
--- /dev/null
+++ b/src/encoding/TextXMLCodec.js
@@ -0,0 +1 @@
+//TODO
\ No newline at end of file
diff --git a/src/encoding/TextXMLDecoder.js b/src/encoding/TextXMLDecoder.js
new file mode 100644
index 0000000..ea64188
--- /dev/null
+++ b/src/encoding/TextXMLDecoder.js
@@ -0,0 +1 @@
+//TODO
\ No newline at end of file
diff --git a/src/encoding/TextXMLEncoder.js b/src/encoding/TextXMLEncoder.js
new file mode 100644
index 0000000..ea64188
--- /dev/null
+++ b/src/encoding/TextXMLEncoder.js
@@ -0,0 +1 @@
+//TODO
\ No newline at end of file