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
11 changes: 9 additions & 2 deletions packages/protons/src/types/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,13 @@ export interface ${this.pbType}Input {
streamGeneratorEvents.push('{}')
}

// the only decode options are repeated field limits, so only declare the
// variable if we have repeated fields or a sub message field to pass
// options to
const decodeOpts = this.fields.some(field => field instanceof ArrayField || field instanceof MapField || field instanceof MessageField)
? ', opts = {}'
: ''

interfaceCodecDef = `
let _codec: Codec<${this.pbType}, ${this.pbType}Input>

Expand All @@ -309,7 +316,7 @@ export interface ${this.pbType}Input {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length${decodeOpts}) => {
const obj: any = {${this.createDefaultObject()}}

const end = length == null ? r.len : r.pos + length
Expand All @@ -326,7 +333,7 @@ export interface ${this.pbType}Input {
}
${enforceOneOfDecoding === '' ? '' : `${enforceOneOfDecoding}\n`}
return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix${decodeOpts}) {
${this.createLimitObject()}const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down
8 changes: 4 additions & 4 deletions packages/protons/test/fixtures/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export namespace Basic {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
num: 0
}
Expand All @@ -62,7 +62,7 @@ export namespace Basic {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down Expand Up @@ -151,7 +151,7 @@ export namespace Empty {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {}

const end = length == null ? r.len : r.pos + length
Expand All @@ -168,7 +168,7 @@ export namespace Empty {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down
12 changes: 6 additions & 6 deletions packages/protons/test/fixtures/bitswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export namespace Message {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
block: uint8ArrayAlloc(0),
priority: 0,
Expand Down Expand Up @@ -143,7 +143,7 @@ export namespace Message {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down Expand Up @@ -468,7 +468,7 @@ export namespace Message {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
prefix: uint8ArrayAlloc(0),
data: uint8ArrayAlloc(0)
Expand Down Expand Up @@ -496,7 +496,7 @@ export namespace Message {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down Expand Up @@ -617,7 +617,7 @@ export namespace Message {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
cid: uint8ArrayAlloc(0),
type: BlockPresenceType.Have
Expand Down Expand Up @@ -645,7 +645,7 @@ export namespace Message {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
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 @@ -58,7 +58,7 @@ export namespace CustomOptionNumber {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
key: 0,
value: 0
Expand Down Expand Up @@ -86,7 +86,7 @@ export namespace CustomOptionNumber {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down Expand Up @@ -523,7 +523,7 @@ export namespace CustomOptionString {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
key: '',
value: ''
Expand Down Expand Up @@ -551,7 +551,7 @@ export namespace CustomOptionString {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down
24 changes: 12 additions & 12 deletions packages/protons/test/fixtures/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ export namespace ErrorResponse {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
msg: ''
}
Expand All @@ -1695,7 +1695,7 @@ export namespace ErrorResponse {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down Expand Up @@ -1795,7 +1795,7 @@ export namespace StreamInfo {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
peer: uint8ArrayAlloc(0),
addr: uint8ArrayAlloc(0),
Expand Down Expand Up @@ -1828,7 +1828,7 @@ export namespace StreamInfo {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down Expand Up @@ -2010,7 +2010,7 @@ export namespace DHTRequest {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
type: Type.FIND_PEER
}
Expand Down Expand Up @@ -2057,7 +2057,7 @@ export namespace DHTRequest {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down Expand Up @@ -2597,7 +2597,7 @@ export namespace ConnManagerRequest {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
type: Type.TAG_PEER
}
Expand Down Expand Up @@ -2632,7 +2632,7 @@ export namespace ConnManagerRequest {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down Expand Up @@ -2754,7 +2754,7 @@ export namespace DisconnectRequest {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
peer: uint8ArrayAlloc(0)
}
Expand All @@ -2777,7 +2777,7 @@ export namespace DisconnectRequest {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down Expand Up @@ -2897,7 +2897,7 @@ export namespace PSRequest {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
type: Type.GET_TOPICS
}
Expand Down Expand Up @@ -2928,7 +2928,7 @@ export namespace PSRequest {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down
4 changes: 2 additions & 2 deletions packages/protons/test/fixtures/dht.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export namespace Record {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {}

const end = length == null ? r.len : r.pos + length
Expand Down Expand Up @@ -93,7 +93,7 @@ export namespace Record {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down
16 changes: 8 additions & 8 deletions packages/protons/test/fixtures/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export namespace MapTypes {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
key: '',
value: ''
Expand Down Expand Up @@ -265,7 +265,7 @@ export namespace MapTypes {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down Expand Up @@ -370,7 +370,7 @@ export namespace MapTypes {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
key: 0,
value: 0
Expand Down Expand Up @@ -398,7 +398,7 @@ export namespace MapTypes {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down Expand Up @@ -503,7 +503,7 @@ export namespace MapTypes {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
key: false,
value: false
Expand Down Expand Up @@ -531,7 +531,7 @@ export namespace MapTypes {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down Expand Up @@ -786,7 +786,7 @@ export namespace MapTypes {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
key: '',
value: EnumValue.NO_VALUE
Expand Down Expand Up @@ -814,7 +814,7 @@ export namespace MapTypes {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down
8 changes: 4 additions & 4 deletions packages/protons/test/fixtures/noise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export namespace pb {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {
identityKey: uint8ArrayAlloc(0),
identitySig: uint8ArrayAlloc(0),
Expand Down Expand Up @@ -81,7 +81,7 @@ export namespace pb {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down Expand Up @@ -177,7 +177,7 @@ export namespace pb {
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (r, length, opts = {}) => {
}, (r, length) => {
const obj: any = {}

const end = length == null ? r.len : r.pos + length
Expand All @@ -194,7 +194,7 @@ export namespace pb {
}

return obj
}, function * (r, length, prefix, opts = {}) {
}, function * (r, length, prefix) {
const end = length == null ? r.len : r.pos + length

if (prefix !== '.') {
Expand Down
Loading
Loading