// Copyright 2014 Cognitect. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

goog.provide("com.cognitect.transit.impl.reader");
goog.require("com.cognitect.transit.impl.decoder");
goog.require("com.cognitect.transit.caching");

goog.scope(function() {

var reader  = com.cognitect.transit.impl.reader,
    decoder = com.cognitect.transit.impl.decoder,
    caching = com.cognitect.transit.caching;

/**
 * A JSON unmarshaller
 * @constructor
 */
reader.JSONUnmarshaller = function(opts) {
    this.decoder = new decoder.Decoder(opts);
};

/**
 * @param {string} str a JSON string
 * @param {caching.ReadCache} cache a read cache
 * @returns {*}
 */
reader.JSONUnmarshaller.prototype.unmarshal = function(str, cache) {
    return this.decoder.decode(JSON.parse(str), cache);
};

/**
 * A transit reader
 * @constructor
 * @param {reader.JSONUnmarshaller} unmarshaller
 * @param {Object} options
 */
reader.Reader = function(unmarshaller, options) {
    this.unmarshaller = unmarshaller;
    this.options = options || {};
    this.cache = this.options["cache"] ? this.options["cache"] : new caching.ReadCache();
};

/**
 * @param {string} str a string to be read
 * @returns {Object}
 */
reader.Reader.prototype.read = function(str) {
    var ret = this.unmarshaller.unmarshal(str, this.cache)
    this.cache.clear();
    return ret;
};
reader.Reader.prototype["read"] = reader.Reader.prototype.read;

});

@@ -777,14 +777,19 @@
 tion
+ 
 () %7B%0A%0A
+    
 var 
@@ -837,16 +837,20 @@
 er,%0A    
+ 
+   
 decoder 
@@ -891,16 +891,20 @@
 er,%0A    
+  
+  
 caching 
@@ -937,20 +937,28 @@
 ching;%0A%0A
-/**%0A
+    /**%0A    
  * A JSO
@@ -968,24 +968,28 @@
 nmarshaller%0A
+    
  * @construc
@@ -993,19 +993,27 @@
 ructor%0A 
-*/%0A
+    */%0A    
 reader.J
@@ -1038,16 +1038,17 @@
 function
+ 
 (opts) %7B
@@ -1048,24 +1048,28 @@
 opts) %7B%0A    
+   
+ 
 this.decoder
@@ -1098,24 +1098,36 @@
 (opts);%0A
-%7D;%0A%0A/**%0A
+    %7D;%0A%0A    /**%0A    
  * @para
@@ -1155,16 +1155,20 @@
  string%0A
+    
  * @para
@@ -1208,16 +1208,20 @@
 d cache%0A
+    
  * @retu
@@ -1229,19 +1229,27 @@
 ns %7B*%7D%0A 
-*/%0A
+    */%0A    
 reader.J
@@ -1290,24 +1290,25 @@
 l = function
+ 
 (str, cache)
@@ -1310,24 +1310,28 @@
 ache) %7B%0A    
+  
+  
 return this.
@@ -1370,24 +1370,36 @@
 cache);%0A
-%7D;%0A%0A/**%0A
+    %7D;%0A%0A    /**%0A    
  * A tra
@@ -1410,16 +1410,20 @@
  reader%0A
+    
  * @cons
@@ -1430,16 +1430,20 @@
 tructor%0A
+    
  * @para
@@ -1483,16 +1483,20 @@
 shaller%0A
+    
  * @para
@@ -1515,19 +1515,27 @@
 ptions%0A 
-*/%0A
+    */%0A    
 reader.R
@@ -1550,16 +1550,17 @@
 function
+ 
 (unmarsh
@@ -1577,24 +1577,28 @@
 ions) %7B%0A    
+ 
+   
 this.unmarsh
@@ -1619,24 +1619,28 @@
 haller;%0A    
+   
+ 
 this.options
@@ -1657,16 +1657,20 @@
  %7C%7C %7B%7D;%0A
+    
     this
@@ -1755,16 +1755,28 @@
 ();%0A
-%7D;%0A%0A
+    %7D;%0A%0A    
 /**%0A
+    
  * @
@@ -1814,16 +1814,20 @@
 be read%0A
+    
  * @retu
@@ -1835,20 +1835,23 @@
 ns %7B
-Object%7D%0A */%0A
+*%7D%0A     */%0A    
 read
@@ -1889,16 +1889,17 @@
 tion
+ 
 (str) %7B%0A
     
@@ -1890,24 +1890,28 @@
 ion (str) %7B%0A
+    
     var ret 
@@ -1957,16 +1957,20 @@
 .cache)%0A
+    
     this
@@ -1985,24 +1985,28 @@
 lear();%0A    
+  
+  
 return ret;%0A
@@ -2005,19 +2005,27 @@
 rn ret;%0A
-%7D;%0A
+    %7D;%0A    
 reader.R

reformat reader