json-as 0.5.54 → 0.5.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -90,22 +90,39 @@ class AsJSONTransform extends BaseVisitor {
90
90
  "i16",
91
91
  "u32",
92
92
  "i32",
93
- "f32",
94
93
  "u64",
95
94
  "i64",
95
+ ].includes(type.toLowerCase())) {
96
+ this.currentClass.encodeStmts.push(`"${name}":\${this.${name}.toString()},`);
97
+ // @ts-ignore
98
+ this.currentClass.setDataStmts.push(`if (key.equals("${name}")) {
99
+ this.${name} = __atoi_fast<${type}>(data, val_start << 1, val_end << 1);
100
+ return;
101
+ }
102
+ `);
103
+ }
104
+ else // @ts-ignore
105
+ if ([
106
+ "f32",
96
107
  "f64",
97
108
  ].includes(type.toLowerCase())) {
98
109
  this.currentClass.encodeStmts.push(`"${name}":\${this.${name}.toString()},`);
110
+ // @ts-ignore
111
+ this.currentClass.setDataStmts.push(`if (key.equals("${name}")) {
112
+ this.${name} = __parseObjectValue<${type}>(data.slice(val_start, val_end));
113
+ return;
114
+ }
115
+ `);
99
116
  }
100
117
  else {
101
118
  this.currentClass.encodeStmts.push(`"${name}":\${JSON.stringify<${type}>(this.${name})},`);
102
- }
103
- // @ts-ignore
104
- this.currentClass.setDataStmts.push(`if (key == "${name}") {
105
- this.${name} = JSON.parseObjectValue<${type}>(value);
119
+ // @ts-ignore
120
+ this.currentClass.setDataStmts.push(`if (key.equals("${name}")) {
121
+ this.${name} = __parseObjectValue<${type}>(val_start ? data.slice(val_start, val_end) : data);
106
122
  return;
107
123
  }
108
124
  `);
125
+ }
109
126
  }
110
127
  }
111
128
  let serializeFunc = "";
@@ -114,23 +131,20 @@ class AsJSONTransform extends BaseVisitor {
114
131
  this.currentClass.encodeStmts[this.currentClass.encodeStmts.length - 1] =
115
132
  stmt.slice(0, stmt.length - 1);
116
133
  serializeFunc = `
117
- @inline
118
- __JSON_Serialize(): string {
134
+ @inline __JSON_Serialize(): string {
119
135
  return \`{${this.currentClass.encodeStmts.join("")}}\`;
120
136
  }
121
137
  `;
122
138
  }
123
139
  else {
124
140
  serializeFunc = `
125
- @inline
126
- __JSON_Serialize(): string {
141
+ @inline __JSON_Serialize(): string {
127
142
  return "{}";
128
143
  }
129
144
  `;
130
145
  }
131
146
  const setKeyFunc = `
132
- @inline
133
- __JSON_Set_Key(key: string, value: string): void {
147
+ @inline __JSON_Set_Key<T>(key: T, data: string, val_start: i32, val_end: i32): void {
134
148
  ${
135
149
  // @ts-ignore
136
150
  this.currentClass.setDataStmts.join("")}
@@ -141,6 +155,7 @@ class AsJSONTransform extends BaseVisitor {
141
155
  const setDataMethod = SimpleParser.parseClassMember(setKeyFunc, node);
142
156
  node.members.push(setDataMethod);
143
157
  this.schemasList.push(this.currentClass);
158
+ //console.log(toString(node));
144
159
  }
145
160
  visitSource(node) {
146
161
  super.visitSource(node);
@@ -23,7 +23,7 @@ class AsJSONTransform extends BaseVisitor {
23
23
  public currentClass!: SchemaData;
24
24
  public sources: Source[] = [];
25
25
 
26
- visitMethodDeclaration(): void {}
26
+ visitMethodDeclaration(): void { }
27
27
  visitClassDeclaration(node: ClassDeclaration): void {
28
28
  const className = node.name.text;
29
29
  if (!node.decorators?.length) return;
@@ -65,8 +65,8 @@ class AsJSONTransform extends BaseVisitor {
65
65
  } else {
66
66
  console.error(
67
67
  "Class extends " +
68
- this.currentClass.parent +
69
- ", but parent class not found. Maybe add the @json decorator over parent class?"
68
+ this.currentClass.parent +
69
+ ", but parent class not found. Maybe add the @json decorator over parent class?"
70
70
  );
71
71
  }
72
72
  }
@@ -103,28 +103,52 @@ class AsJSONTransform extends BaseVisitor {
103
103
  "i16",
104
104
  "u32",
105
105
  "i32",
106
- "f32",
107
106
  "u64",
108
107
  "i64",
109
- "f64",
110
108
  ].includes(type.toLowerCase())
111
109
  ) {
112
110
  this.currentClass.encodeStmts.push(
113
111
  `"${name}":\${this.${name}.toString()},`
114
112
  );
115
- } else {
113
+ // @ts-ignore
114
+ this.currentClass.setDataStmts.push(
115
+ `if (key.equals("${name}")) {
116
+ this.${name} = __atoi_fast<${type}>(data, val_start << 1, val_end << 1);
117
+ return;
118
+ }
119
+ `
120
+ );
121
+ } else // @ts-ignore
122
+ if (
123
+ [
124
+ "f32",
125
+ "f64",
126
+ ].includes(type.toLowerCase())
127
+ ) {
128
+ this.currentClass.encodeStmts.push(
129
+ `"${name}":\${this.${name}.toString()},`
130
+ );
131
+ // @ts-ignore
132
+ this.currentClass.setDataStmts.push(
133
+ `if (key.equals("${name}")) {
134
+ this.${name} = __parseObjectValue<${type}>(data.slice(val_start, val_end));
135
+ return;
136
+ }
137
+ `
138
+ );
139
+ } else {
116
140
  this.currentClass.encodeStmts.push(
117
141
  `"${name}":\${JSON.stringify<${type}>(this.${name})},`
118
142
  );
119
- }
120
- // @ts-ignore
121
- this.currentClass.setDataStmts.push(
122
- `if (key == "${name}") {
123
- this.${name} = JSON.parseObjectValue<${type}>(value);
143
+ // @ts-ignore
144
+ this.currentClass.setDataStmts.push(
145
+ `if (key.equals("${name}")) {
146
+ this.${name} = __parseObjectValue<${type}>(val_start ? data.slice(val_start, val_end) : data);
124
147
  return;
125
148
  }
126
149
  `
127
- );
150
+ );
151
+ }
128
152
  }
129
153
  }
130
154
 
@@ -133,32 +157,29 @@ class AsJSONTransform extends BaseVisitor {
133
157
  if (this.currentClass.encodeStmts.length > 0) {
134
158
  const stmt =
135
159
  this.currentClass.encodeStmts[
136
- this.currentClass.encodeStmts.length - 1
160
+ this.currentClass.encodeStmts.length - 1
137
161
  ]!;
138
162
  this.currentClass.encodeStmts[this.currentClass.encodeStmts.length - 1] =
139
163
  stmt!.slice(0, stmt.length - 1);
140
164
  serializeFunc = `
141
- @inline
142
- __JSON_Serialize(): string {
165
+ @inline __JSON_Serialize(): string {
143
166
  return \`{${this.currentClass.encodeStmts.join("")}}\`;
144
167
  }
145
168
  `;
146
169
  } else {
147
170
  serializeFunc = `
148
- @inline
149
- __JSON_Serialize(): string {
171
+ @inline __JSON_Serialize(): string {
150
172
  return "{}";
151
173
  }
152
174
  `;
153
175
  }
154
176
 
155
177
  const setKeyFunc = `
156
- @inline
157
- __JSON_Set_Key(key: string, value: string): void {
178
+ @inline __JSON_Set_Key<T>(key: T, data: string, val_start: i32, val_end: i32): void {
158
179
  ${
159
- // @ts-ignore
160
- this.currentClass.setDataStmts.join("")
161
- }
180
+ // @ts-ignore
181
+ this.currentClass.setDataStmts.join("")
182
+ }
162
183
  }
163
184
  `;
164
185
 
@@ -169,6 +190,7 @@ class AsJSONTransform extends BaseVisitor {
169
190
  node.members.push(setDataMethod);
170
191
 
171
192
  this.schemasList.push(this.currentClass);
193
+ //console.log(toString(node));
172
194
  }
173
195
  visitSource(node: Source): void {
174
196
  super.visitSource(node);