Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/protons/src/fields/array-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ArrayField extends Field {
}

return `
if (obj.${this.name} != null) {
if (obj.${this.name} != null && obj.${this.name}.length > 0) {
for (const value of obj.${this.name}) {
w.uint32(${id})
${type.getEncoder(this, 'value')}
Expand Down
2 changes: 1 addition & 1 deletion packages/protons/src/fields/map-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class MapField extends Field {
const entryType = parent.findType(this.entryType)

return `
if (${entryType.getValueTest(this, 'value')}) {
if (obj.${this.name} != null && obj.${this.name}.size > 0) {
for (const [key, value] of obj.${this.name}.entries()) {
w.uint32(${id})
${entryType.getEncoder(this, '{ key, value }')}
Expand Down
8 changes: 4 additions & 4 deletions packages/protons/test/fixtures/bitswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export namespace Message {
w.fork()
}

if (obj.entries != null) {
if (obj.entries != null && obj.entries.length > 0) {
for (const value of obj.entries) {
w.uint32(10)
Message.Wantlist.Entry.codec().encode(value, w)
Expand Down Expand Up @@ -622,21 +622,21 @@ export namespace Message {
Message.Wantlist.codec().encode(obj.wantlist, w)
}

if (obj.blocks != null) {
if (obj.blocks != null && obj.blocks.length > 0) {
for (const value of obj.blocks) {
w.uint32(18)
w.bytes(value)
}
}

if (obj.payload != null) {
if (obj.payload != null && obj.payload.length > 0) {
for (const value of obj.payload) {
w.uint32(26)
Message.Block.codec().encode(value, w)
}
}

if (obj.blockPresences != null) {
if (obj.blockPresences != null && obj.blockPresences.length > 0) {
for (const value of obj.blockPresences) {
w.uint32(34)
Message.BlockPresence.codec().encode(value, w)
Expand Down
2 changes: 1 addition & 1 deletion packages/protons/test/fixtures/circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export namespace CircuitRelay {
w.bytes(obj.id)
}

if (obj.addrs != null) {
if (obj.addrs != null && obj.addrs.length > 0) {
for (const value of obj.addrs) {
w.uint32(18)
w.bytes(value)
Expand Down
8 changes: 4 additions & 4 deletions packages/protons/test/fixtures/custom-option-jstype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,14 @@ export namespace CustomOptionNumber {
w.sfixed64Number(obj.sf64)
}

if (obj.i64Array != null) {
if (obj.i64Array != null && obj.i64Array.length > 0) {
for (const value of obj.i64Array) {
w.uint32(56)
w.int64Number(value)
}
}

if (obj.i64Map != null) {
if (obj.i64Map != null && obj.i64Map.size > 0) {
for (const [key, value] of obj.i64Map.entries()) {
w.uint32(66)
CustomOptionNumber.CustomOptionNumber$i64MapEntry.codec().encode({ key, value }, w)
Expand Down Expand Up @@ -567,14 +567,14 @@ export namespace CustomOptionString {
w.sfixed64String(obj.sf64)
}

if (obj.i64Array != null) {
if (obj.i64Array != null && obj.i64Array.length > 0) {
for (const value of obj.i64Array) {
w.uint32(56)
w.int64String(value)
}
}

if (obj.i64Map != null) {
if (obj.i64Map != null && obj.i64Map.size > 0) {
for (const [key, value] of obj.i64Map.entries()) {
w.uint32(66)
CustomOptionString.CustomOptionString$i64MapEntry.codec().encode({ key, value }, w)
Expand Down
22 changes: 11 additions & 11 deletions packages/protons/test/fixtures/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ export namespace Response {
DHTResponse.codec().encode(obj.dht, w)
}

if (obj.peers != null) {
if (obj.peers != null && obj.peers.length > 0) {
for (const value of obj.peers) {
w.uint32(50)
PeerInfo.codec().encode(value, w)
Expand Down Expand Up @@ -783,7 +783,7 @@ export namespace IdentifyResponse {
w.bytes(obj.id)
}

if (obj.addrs != null) {
if (obj.addrs != null && obj.addrs.length > 0) {
for (const value of obj.addrs) {
w.uint32(18)
w.bytes(value)
Expand Down Expand Up @@ -915,7 +915,7 @@ export namespace ConnectRequest {
w.bytes(obj.peer)
}

if (obj.addrs != null) {
if (obj.addrs != null && obj.addrs.length > 0) {
for (const value of obj.addrs) {
w.uint32(18)
w.bytes(value)
Expand Down Expand Up @@ -1068,7 +1068,7 @@ export namespace StreamOpenRequest {
w.bytes(obj.peer)
}

if (obj.proto != null) {
if (obj.proto != null && obj.proto.length > 0) {
for (const value of obj.proto) {
w.uint32(18)
w.string(value)
Expand Down Expand Up @@ -1220,7 +1220,7 @@ export namespace StreamHandlerRequest {
w.bytes(obj.addr)
}

if (obj.proto != null) {
if (obj.proto != null && obj.proto.length > 0) {
for (const value of obj.proto) {
w.uint32(18)
w.string(value)
Expand Down Expand Up @@ -1985,7 +1985,7 @@ export namespace PeerInfo {
w.bytes(obj.id)
}

if (obj.addrs != null) {
if (obj.addrs != null && obj.addrs.length > 0) {
for (const value of obj.addrs) {
w.uint32(18)
w.bytes(value)
Expand Down Expand Up @@ -2545,7 +2545,7 @@ export namespace PSMessage {
w.bytes(obj.seqno)
}

if (obj.topicIDs != null) {
if (obj.topicIDs != null && obj.topicIDs.length > 0) {
for (const value of obj.topicIDs) {
w.uint32(34)
w.string(value)
Expand Down Expand Up @@ -2744,14 +2744,14 @@ export namespace PSResponse {
w.fork()
}

if (obj.topics != null) {
if (obj.topics != null && obj.topics.length > 0) {
for (const value of obj.topics) {
w.uint32(10)
w.string(value)
}
}

if (obj.peerIDs != null) {
if (obj.peerIDs != null && obj.peerIDs.length > 0) {
for (const value of obj.peerIDs) {
w.uint32(18)
w.bytes(value)
Expand Down Expand Up @@ -2920,7 +2920,7 @@ export namespace PeerstoreRequest {
w.bytes(obj.id)
}

if (obj.protos != null) {
if (obj.protos != null && obj.protos.length > 0) {
for (const value of obj.protos) {
w.uint32(26)
w.string(value)
Expand Down Expand Up @@ -3067,7 +3067,7 @@ export namespace PeerstoreResponse {
PeerInfo.codec().encode(obj.peer, w)
}

if (obj.protos != null) {
if (obj.protos != null && obj.protos.length > 0) {
for (const value of obj.protos) {
w.uint32(18)
w.string(value)
Expand Down
6 changes: 3 additions & 3 deletions packages/protons/test/fixtures/dht.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export namespace Message {
w.bytes(obj.id)
}

if (obj.addrs != null) {
if (obj.addrs != null && obj.addrs.length > 0) {
for (const value of obj.addrs) {
w.uint32(18)
w.bytes(value)
Expand Down Expand Up @@ -412,14 +412,14 @@ export namespace Message {
w.bytes(obj.record)
}

if (obj.closerPeers != null) {
if (obj.closerPeers != null && obj.closerPeers.length > 0) {
for (const value of obj.closerPeers) {
w.uint32(66)
Message.Peer.codec().encode(value, w)
}
}

if (obj.providerPeers != null) {
if (obj.providerPeers != null && obj.providerPeers.length > 0) {
for (const value of obj.providerPeers) {
w.uint32(74)
Message.Peer.codec().encode(value, w)
Expand Down
12 changes: 6 additions & 6 deletions packages/protons/test/fixtures/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export namespace SubMessage {
w.string(obj.foo)
}

if (obj.bar != null) {
if (obj.bar != null && obj.bar.length > 0) {
for (const value of obj.bar) {
w.uint32(16)
w.uint32(value)
Expand Down Expand Up @@ -736,35 +736,35 @@ export namespace MapTypes {
w.fork()
}

if (obj.stringMap != null) {
if (obj.stringMap != null && obj.stringMap.size > 0) {
for (const [key, value] of obj.stringMap.entries()) {
w.uint32(10)
MapTypes.MapTypes$stringMapEntry.codec().encode({ key, value }, w)
}
}

if (obj.intMap != null) {
if (obj.intMap != null && obj.intMap.size > 0) {
for (const [key, value] of obj.intMap.entries()) {
w.uint32(18)
MapTypes.MapTypes$intMapEntry.codec().encode({ key, value }, w)
}
}

if (obj.boolMap != null) {
if (obj.boolMap != null && obj.boolMap.size > 0) {
for (const [key, value] of obj.boolMap.entries()) {
w.uint32(26)
MapTypes.MapTypes$boolMapEntry.codec().encode({ key, value }, w)
}
}

if (obj.messageMap != null) {
if (obj.messageMap != null && obj.messageMap.size > 0) {
for (const [key, value] of obj.messageMap.entries()) {
w.uint32(34)
MapTypes.MapTypes$messageMapEntry.codec().encode({ key, value }, w)
}
}

if (obj.enumMap != null) {
if (obj.enumMap != null && obj.enumMap.size > 0) {
for (const [key, value] of obj.enumMap.entries()) {
w.uint32(42)
MapTypes.MapTypes$enumMapEntry.codec().encode({ key, value }, w)
Expand Down
6 changes: 3 additions & 3 deletions packages/protons/test/fixtures/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ export namespace Peer {
w.fork()
}

if (obj.addresses != null) {
if (obj.addresses != null && obj.addresses.length > 0) {
for (const value of obj.addresses) {
w.uint32(10)
Address.codec().encode(value, w)
}
}

if (obj.protocols != null) {
if (obj.protocols != null && obj.protocols.length > 0) {
for (const value of obj.protocols) {
w.uint32(18)
w.string(value)
}
}

if (obj.metadata != null) {
if (obj.metadata != null && obj.metadata.length > 0) {
for (const value of obj.metadata) {
w.uint32(26)
Metadata.codec().encode(value, w)
Expand Down
4 changes: 2 additions & 2 deletions packages/protons/test/fixtures/protons-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export namespace MessageWithSizeLimitedRepeatedField {
w.fork()
}

if (obj.repeatedField != null) {
if (obj.repeatedField != null && obj.repeatedField.length > 0) {
for (const value of obj.repeatedField) {
w.uint32(10)
w.string(value)
Expand Down Expand Up @@ -244,7 +244,7 @@ export namespace MessageWithSizeLimitedMap {
w.fork()
}

if (obj.mapField != null) {
if (obj.mapField != null && obj.mapField.size > 0) {
for (const [key, value] of obj.mapField.entries()) {
w.uint32(10)
MessageWithSizeLimitedMap.MessageWithSizeLimitedMap$mapFieldEntry.codec().encode({ key, value }, w)
Expand Down
12 changes: 6 additions & 6 deletions packages/protons/test/fixtures/repeated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export namespace SubSubMessage {
w.fork()
}

if (obj.foo != null) {
if (obj.foo != null && obj.foo.length > 0) {
for (const value of obj.foo) {
w.uint32(10)
w.string(value)
Expand Down Expand Up @@ -149,7 +149,7 @@ export namespace SubMessage {
w.fork()
}

if (obj.foo != null) {
if (obj.foo != null && obj.foo.length > 0) {
for (const value of obj.foo) {
w.uint32(10)
w.string(value)
Expand All @@ -166,7 +166,7 @@ export namespace SubMessage {
SubSubMessage.codec().encode(obj.message, w)
}

if (obj.messages != null) {
if (obj.messages != null && obj.messages.length > 0) {
for (const value of obj.messages) {
w.uint32(34)
SubSubMessage.codec().encode(value, w)
Expand Down Expand Up @@ -360,21 +360,21 @@ export namespace RepeatedTypes {
w.fork()
}

if (obj.number != null) {
if (obj.number != null && obj.number.length > 0) {
for (const value of obj.number) {
w.uint32(8)
w.uint32(value)
}
}

if (obj.limitedNumber != null) {
if (obj.limitedNumber != null && obj.limitedNumber.length > 0) {
for (const value of obj.limitedNumber) {
w.uint32(16)
w.uint32(value)
}
}

if (obj.messages != null) {
if (obj.messages != null && obj.messages.length > 0) {
for (const value of obj.messages) {
w.uint32(26)
SubMessage.codec().encode(value, w)
Expand Down
8 changes: 4 additions & 4 deletions packages/protons/test/fixtures/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export namespace MessageWithArrayField {
w.uint32(obj.field2)
}

if (obj.arr != null) {
if (obj.arr != null && obj.arr.length > 0) {
for (const value of obj.arr) {
w.uint32(26)
w.string(value)
Expand Down Expand Up @@ -494,7 +494,7 @@ export namespace MessageWithRepeatedMessage {
w.bool(obj.field1)
}

if (obj.nestedMessages != null) {
if (obj.nestedMessages != null && obj.nestedMessages.length > 0) {
for (const value of obj.nestedMessages) {
w.uint32(18)
NestedMessage.codec().encode(value, w)
Expand Down Expand Up @@ -743,7 +743,7 @@ export namespace MessageWithMapMessage {
w.bool(obj.field1)
}

if (obj.nestedMessages != null) {
if (obj.nestedMessages != null && obj.nestedMessages.size > 0) {
for (const [key, value] of obj.nestedMessages.entries()) {
w.uint32(18)
MessageWithMapMessage.MessageWithMapMessage$nestedMessagesEntry.codec().encode({ key, value }, w)
Expand Down Expand Up @@ -991,7 +991,7 @@ export namespace MessageWithPrimitiveMap {
w.bool(obj.field1)
}

if (obj.nestedStrings != null) {
if (obj.nestedStrings != null && obj.nestedStrings.size > 0) {
for (const [key, value] of obj.nestedStrings.entries()) {
w.uint32(18)
MessageWithPrimitiveMap.MessageWithPrimitiveMap$nestedStringsEntry.codec().encode({ key, value }, w)
Expand Down
Loading
Loading