From 04a3f72130135f4fd3ee1d830cfb37f7d78b9e55 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Sat, 9 May 2015 16:08:54 +0200 Subject: [PATCH] readCondition now return value==null when the condition is not met instead of returning null (when read returns null it means there was an error), check if value is null in readContainer and parsePacketData and don't include it if so, improve "field x missing" error message in test.js a bit --- src/protocol.js | 8 ++++---- test/test.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/protocol.js b/src/protocol.js index 00a4b6f..5444447 100644 --- a/src/protocol.js +++ b/src/protocol.js @@ -123,7 +123,7 @@ for (var n in entityMetadataTypes) { function readCondition(buffer,offset,typeArgs, rootNode) { if(!evalCondition(typeArgs,rootNode)) - return null; + return { value: null, size: 0 }; return read(buffer, offset, { type: typeArgs.type, typeArgs:typeArgs.typeArgs }, rootNode); } @@ -546,7 +546,7 @@ function readContainer(buffer, offset, typeArgs, rootNode) { rootNode.this = results.value; for (var index in typeArgs.fields) { var readResults = read(buffer, offset, typeArgs.fields[index], rootNode); - if (readResults == null) { continue; } + if (readResults == null || readResults.value==null) { continue; } results.size += readResults.size; offset += readResults.size; results.value[typeArgs.fields[index].name] = readResults.value; @@ -680,7 +680,7 @@ function read(buffer, cursor, fieldInfo, rootNodes) { }; } var readResults = type[0](buffer, cursor, fieldInfo.typeArgs, rootNodes); - if (readResults == null && fieldInfo.type!=="condition") { + if (readResults == null) { throw new Error("Reader returned null : " + JSON.stringify(fieldInfo)); } if (readResults && readResults.error) return { error: readResults.error }; @@ -829,7 +829,7 @@ function parsePacketData(buffer, state, isServer, packetsToParse) { results: results }; }*/ - if (readResults === null) continue; + if (readResults === null || readResults.value==null) continue; if (readResults.error) { return readResults; } diff --git a/test/test.js b/test/test.js index b05a355..d1456fa 100644 --- a/test/test.js +++ b/test/test.js @@ -213,10 +213,10 @@ describe("packets", function() { }); var field; for (field in p1) { - assert.ok(field in p2, "field " + field + " missing in p2"); + assert.ok(field in p2, "field " + field + " missing in p2, in p1 it has value "+JSON.stringify(p1[field])); } for (field in p2) { - assert.ok(field in p1, "field " + field + " missing in p1"); + assert.ok(field in p1, "field " + field + " missing in p1, in p2 it has value "+JSON.stringify(p2[field])); } } });