-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve test coverage for generated code
- Loading branch information
Showing
19 changed files
with
358 additions
and
45 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
export const MessageType = { | ||
"UNKNOWN": 0, | ||
"GREETING": 1 | ||
}; | ||
|
||
export function readEnvelope(pbf, end) { | ||
return pbf.readFields(readEnvelopeField, {type: 1, name: "test", flag: true, weight: 1.5, id: 1}, end); | ||
} | ||
function readEnvelopeField(tag, obj, pbf) { | ||
if (tag === 1) obj.type = pbf.readVarint(); | ||
else if (tag === 2) obj.name = pbf.readString(); | ||
else if (tag === 3) obj.flag = pbf.readBoolean(); | ||
else if (tag === 4) obj.weight = pbf.readFloat(); | ||
else if (tag === 5) obj.id = pbf.readVarint(true); | ||
} | ||
export function writeEnvelope(obj, pbf) { | ||
if (obj.type != null && obj.type !== 1) pbf.writeVarintField(1, obj.type); | ||
if (obj.name != null && obj.name !== "test") pbf.writeStringField(2, obj.name); | ||
if (obj.flag != null && obj.flag !== true) pbf.writeBooleanField(3, obj.flag); | ||
if (obj.weight != null && obj.weight !== 1.5) pbf.writeFloatField(4, obj.weight); | ||
if (obj.id != null && obj.id !== 1) pbf.writeVarintField(5, obj.id); | ||
} |
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,41 @@ | ||
|
||
export const MessageType = { | ||
"UNKNOWN": 0, | ||
"GREETING": 1 | ||
}; | ||
|
||
export function readCustomType(pbf, end) { | ||
return pbf.readFields(readCustomTypeField, {}, end); | ||
} | ||
function readCustomTypeField(tag, obj, pbf) { | ||
} | ||
export function writeCustomType(obj, pbf) { | ||
} | ||
|
||
export function readEnvelope(pbf, end) { | ||
return pbf.readFields(readEnvelopeField, {type: 0, name: "", flag: false, weight: 0, id: 0, tags: [], numbers: [], bytes: undefined, custom: undefined, types: []}, end); | ||
} | ||
function readEnvelopeField(tag, obj, pbf) { | ||
if (tag === 1) obj.type = pbf.readVarint(); | ||
else if (tag === 2) obj.name = pbf.readString(); | ||
else if (tag === 3) obj.flag = pbf.readBoolean(); | ||
else if (tag === 4) obj.weight = pbf.readFloat(); | ||
else if (tag === 5) obj.id = pbf.readVarint(true); | ||
else if (tag === 6) obj.tags.push(pbf.readString()); | ||
else if (tag === 7) pbf.readPackedVarint(obj.numbers, true); | ||
else if (tag === 8) obj.bytes = pbf.readBytes(); | ||
else if (tag === 9) obj.custom = readCustomType(pbf, pbf.readVarint() + pbf.pos); | ||
else if (tag === 10) pbf.readPackedVarint(obj.types); | ||
} | ||
export function writeEnvelope(obj, pbf) { | ||
if (obj.type) pbf.writeVarintField(1, obj.type); | ||
if (obj.name) pbf.writeStringField(2, obj.name); | ||
if (obj.flag) pbf.writeBooleanField(3, obj.flag); | ||
if (obj.weight) pbf.writeFloatField(4, obj.weight); | ||
if (obj.id) pbf.writeVarintField(5, obj.id); | ||
if (obj.tags) for (const item of obj.tags) pbf.writeStringField(6, item); | ||
if (obj.numbers) for (const item of obj.numbers) pbf.writeVarintField(7, item); | ||
if (obj.bytes != null) pbf.writeBytesField(8, obj.bytes); | ||
if (obj.custom) pbf.writeMessage(9, writeCustomType, obj.custom); | ||
if (obj.types) for (const item of obj.types) pbf.writeVarintField(10, item); | ||
} |
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,23 @@ | ||
|
||
export const MessageType = { | ||
"UNKNOWN": 0, | ||
"GREETING": 1 | ||
}; | ||
|
||
export function readEnvelope(pbf, end) { | ||
return pbf.readFields(readEnvelopeField, {type: 0, name: "", flag: false, weight: 0, id: 0}, end); | ||
} | ||
function readEnvelopeField(tag, obj, pbf) { | ||
if (tag === 1) obj.type = pbf.readVarint(); | ||
else if (tag === 2) obj.name = pbf.readString(); | ||
else if (tag === 3) obj.flag = pbf.readBoolean(); | ||
else if (tag === 4) obj.weight = pbf.readFloat(); | ||
else if (tag === 5) obj.id = pbf.readVarint(true); | ||
} | ||
export function writeEnvelope(obj, pbf) { | ||
if (obj.type) pbf.writeVarintField(1, obj.type); | ||
if (obj.name) pbf.writeStringField(2, obj.name); | ||
if (obj.flag) pbf.writeBooleanField(3, obj.flag); | ||
if (obj.weight) pbf.writeFloatField(4, obj.weight); | ||
if (obj.id) pbf.writeVarintField(5, obj.id); | ||
} |
Oops, something went wrong.