You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2014/06/19 22:12:34 UTC

git commit: THRIFT-2576 Implement Thrift.Protocol.prototype.skip method in JavaScript library Client: JavaScript Patch: Hyungsul Kim

Repository: thrift
Updated Branches:
  refs/heads/master 32f398227 -> 329d59aab


THRIFT-2576 Implement Thrift.Protocol.prototype.skip method in JavaScript library
Client: JavaScript
Patch: Hyungsul Kim

This closes #141


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/329d59aa
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/329d59aa
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/329d59aa

Branch: refs/heads/master
Commit: 329d59aab0543171d0af193837db5fec714e0a73
Parents: 32f3982
Author: Jens Geyer <je...@apache.org>
Authored: Thu Jun 19 22:11:53 2014 +0200
Committer: Jens Geyer <je...@apache.org>
Committed: Thu Jun 19 22:11:53 2014 +0200

----------------------------------------------------------------------
 lib/js/src/thrift.js | 74 ++++++++++++++++++++++++++++++++++++++++++++---
 lib/js/test/test.js  | 39 +++++++++++++++++++++++++
 2 files changed, 109 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/329d59aa/lib/js/src/thrift.js
----------------------------------------------------------------------
diff --git a/lib/js/src/thrift.js b/lib/js/src/thrift.js
index 8fc7cd2..6cab4fd 100644
--- a/lib/js/src/thrift.js
+++ b/lib/js/src/thrift.js
@@ -1299,11 +1299,77 @@ Thrift.Protocol.prototype = {
     },
 
     /** 
-     * Method to arbitrarily skip over data (not implemented).
-     * @throws {string} this method is not implemented and always throws.
-     */
+     * Method to arbitrarily skip over data */
     skip: function(type) {
-        throw 'skip not supported yet';
+        var ret, i;
+        switch (type) {
+            case Thrift.Type.STOP:
+                return null;
+
+            case Thrift.Type.BOOL:
+                return this.readBool();
+
+            case Thrift.Type.BYTE:
+                return this.readByte();
+
+            case Thrift.Type.I16:
+                return this.readI16();
+
+            case Thrift.Type.I32:
+                return this.readI32();
+
+            case Thrift.Type.I64:
+                return this.readI64();
+
+            case Thrift.Type.DOUBLE:
+                return this.readDouble();
+
+            case Thrift.Type.STRING:
+                return this.readString();
+
+            case Thrift.Type.STRUCT:
+                this.readStructBegin();
+                while (true) {
+                    ret = this.readFieldBegin();
+                    if (ret.ftype == Thrift.Type.STOP) {
+                        break;
+                    }
+                    this.skip(ret.ftype);
+                    this.readFieldEnd();
+                }
+                this.readStructEnd();
+                return null;
+
+            case Thrift.Type.MAP:
+                ret = this.readMapBegin();
+                for (i = 0; i < ret.size; i++) {
+                    if (i > 0) {
+                        if (this.rstack.length > this.rpos[this.rpos.length - 1] + 1) {
+                            this.rstack.pop();
+                        }
+                    }
+                    this.skip(ret.ktype);
+                    this.skip(ret.vtype);
+                }
+                this.readMapEnd();
+                return null;
+
+            case Thrift.Type.SET:
+                ret = this.readSetBegin();
+                for (i = 0; i < ret.size; i++) {
+                    this.skip(ret.etype);
+                }
+                this.readSetEnd();
+                return null;
+
+            case Thrift.Type.LIST:
+                ret = this.readListBegin();
+                for (i = 0; i < ret.size; i++) {
+                    this.skip(ret.etype);
+                }
+                this.readListEnd();
+                return null;
+        }
     }
 };
 

http://git-wip-us.apache.org/repos/asf/thrift/blob/329d59aa/lib/js/test/test.js
----------------------------------------------------------------------
diff --git a/lib/js/test/test.js b/lib/js/test/test.js
index 7351fd9..1504f62 100755
--- a/lib/js/test/test.js
+++ b/lib/js/test/test.js
@@ -191,6 +191,45 @@ module("Structured Types");
     equal(client.testTypedef(69), 69);
   });
 
+  test("Skip", function() {
+    var structTestInput = new ThriftTest.Xtruct();
+    var modifiedClient = new ThriftTest.ThriftTestClient(protocol);
+
+    modifiedClient.recv_testStruct = function() {
+      var input  = modifiedClient.input;
+      var xtruct3 = new ThriftTest.Xtruct3();
+
+      input.readMessageBegin();
+      input.readStructBegin();
+
+      // read Xtruct data with Xtruct3 
+      input.readFieldBegin();
+      xtruct3.read(input);
+      input.readFieldEnd();
+      // read Thrift.Type.STOP message
+      input.readFieldBegin();
+      input.readFieldEnd();
+
+      input.readStructEnd();
+      input.readMessageEnd();
+
+      return xtruct3;
+    };
+
+    structTestInput.string_thing = 'worked';
+    structTestInput.byte_thing   = 0x01;
+    structTestInput.i32_thing    = Math.pow(2,30);
+    structTestInput.i64_thing    = Math.pow(2,52);
+
+    var structTestOutput = modifiedClient.testStruct(structTestInput);
+
+    equal(structTestOutput instanceof ThriftTest.Xtruct3, true);
+    equal(structTestOutput.string_thing, structTestInput.string_thing);
+    equal(structTestOutput.changed, null);
+    equal(structTestOutput.i32_thing, structTestInput.i32_thing);
+    equal(structTestOutput.i64_thing, structTestInput.i64_thing);
+  });
+
 
 module("deeper!");