-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
const utils = require('../utils'); | ||
|
||
module.exports = (gen, classInfo, version, options) => { | ||
gen('if (obj && obj.$class) { obj = obj.$; }'); | ||
gen('if (obj == null) { return encoder.writeNull(); }'); | ||
gen('if (encoder._checkRef(obj)) { return; }'); | ||
|
||
gen('const hasEnd = encoder._writeListBegin(obj.size || obj.length, \'%s\');', classInfo.type); | ||
|
||
const generic = classInfo.generic; | ||
if (generic && generic.length === 1) { | ||
gen('for (const item of obj) {'); | ||
const genericDefine = utils.normalizeType(generic[0]); | ||
const uniqueId = utils.normalizeUniqId(genericDefine, version); | ||
gen(' let desc;'); | ||
gen(' let val = item;'); | ||
gen(' let uniqueId = \'%s\'', uniqueId); | ||
gen(' if (item && item.$class) {'); | ||
gen(' desc = item;'); | ||
gen(' let type = item.$class;'); | ||
gen(' if (item.isArray) {'); | ||
gen(' let arrayDepth = item.arrayDepth || 1;'); | ||
gen(' while (arrayDepth--) type = \'[\' + type;'); | ||
gen(' }'); | ||
gen(' uniqueId = type;'); | ||
gen(' if (item.generic) {'); | ||
gen(' for (const it of item.generic) {'); | ||
gen(' uniqueId += (\'#\' + it.type);'); | ||
gen(' }'); | ||
gen(' }'); | ||
gen(' uniqueId += \'#\' + version;'); | ||
gen(' val = item.$;'); | ||
gen(' } else {'); | ||
gen(' desc = %j;', genericDefine); | ||
gen(' }'); | ||
gen(' compile(uniqueId, desc, classMap, version, %j)(val, encoder, appClassMap);', options); | ||
gen('}'); | ||
} else { | ||
gen('for (const item of obj) { encoder.write(item); }'); | ||
} | ||
gen('if (hasEnd) { encoder.byteBuffer.putChar(\'z\'); }'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters