Skip to content

Commit

Permalink
Fix union serialization duplicated definition bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xxuejie committed Mar 30, 2020
1 parent 316d749 commit 845fb41
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,17 +511,21 @@ function serializeTable(buffers) {
for i, item := range declaration.Items {
fmt.Fprintf(writer, " case \"%s\":\n", item)
if item == "byte" {
fmt.Fprintf(writer, ` const view = new DataView(new ArrayBuffer(5));
view.setUint32(0, %d, true);
view.setUint8(4, value.value);
return view.buffer;`+"\n", i)
fmt.Fprintf(writer, ` {
const view = new DataView(new ArrayBuffer(5));
view.setUint32(0, %d, true);
view.setUint8(4, value.value);
return view.buffer;
}`+"\n", i)
} else {
fmt.Fprintf(writer, ` const itemBuffer = Serialize%s(value.value);
const array = new Uint8Array(4 + itemBuffer.byteLength);
const view = new DataView(array.buffer);
view.setUint32(0, %d, true);
array.set(new Uint8Array(itemBuffer), 4);
return array.buffer;`+"\n", item, i)
fmt.Fprintf(writer, ` {
const itemBuffer = Serialize%s(value.value);
const array = new Uint8Array(4 + itemBuffer.byteLength);
const view = new DataView(array.buffer);
view.setUint32(0, %d, true);
array.set(new Uint8Array(itemBuffer), 4);
return array.buffer;
}`+"\n", item, i)
}
}
fmt.Fprintln(writer, ` default:
Expand Down

0 comments on commit 845fb41

Please sign in to comment.