Skip to content

Commit

Permalink
chore: fix generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Jul 28, 2022
1 parent caa0d71 commit b6a9c18
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions packages/protons-benchmark/src/protons/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@
/* eslint-disable @typescript-eslint/no-namespace */

import { encodeMessage, decodeMessage, message, uint32, enumeration, string, bytes } from 'protons-runtime'
import type { Codec } from 'protons-runtime'
import type { Uint8ArrayList } from 'uint8arraylist'

export interface Foo {
baz: number
}

export namespace Foo {
export const codec = () => {
export const codec = (): Codec<Foo> => {
return message<Foo>({
1: { name: 'baz', codec: uint32 }
})
}

export const encode = (obj: Foo): Uint8Array => {
export const encode = (obj: Foo): Uint8ArrayList => {
return encodeMessage(obj, Foo.codec())
}

export const decode = (buf: Uint8Array): Foo => {
export const decode = (buf: Uint8Array | Uint8ArrayList): Foo => {
return decodeMessage(buf, Foo.codec())
}
}
Expand All @@ -28,17 +30,17 @@ export interface Bar {
}

export namespace Bar {
export const codec = () => {
export const codec = (): Codec<Bar> => {
return message<Bar>({
1: { name: 'tmp', codec: Foo.codec() }
})
}

export const encode = (obj: Bar): Uint8Array => {
export const encode = (obj: Bar): Uint8ArrayList => {
return encodeMessage(obj, Bar.codec())
}

export const decode = (buf: Uint8Array): Bar => {
export const decode = (buf: Uint8Array | Uint8ArrayList): Bar => {
return decodeMessage(buf, Bar.codec())
}
}
Expand All @@ -48,28 +50,32 @@ export enum FOO {
ABE = 'ABE'
}

enum __FOOValues {
LOL = 1,
ABE = 3
}

export namespace FOO {
export const codec = () => {
return enumeration<typeof FOO>(FOO)
return enumeration<typeof FOO>(__FOOValues)
}
}

export interface Yo {
lol: FOO[]
}

export namespace Yo {
export const codec = () => {
export const codec = (): Codec<Yo> => {
return message<Yo>({
1: { name: 'lol', codec: FOO.codec(), repeats: true }
})
}

export const encode = (obj: Yo): Uint8Array => {
export const encode = (obj: Yo): Uint8ArrayList => {
return encodeMessage(obj, Yo.codec())
}

export const decode = (buf: Uint8Array): Yo => {
export const decode = (buf: Uint8Array | Uint8ArrayList): Yo => {
return decodeMessage(buf, Yo.codec())
}
}
Expand All @@ -80,18 +86,18 @@ export interface Lol {
}

export namespace Lol {
export const codec = () => {
export const codec = (): Codec<Lol> => {
return message<Lol>({
1: { name: 'lol', codec: string },
2: { name: 'b', codec: Bar.codec() }
})
}

export const encode = (obj: Lol): Uint8Array => {
export const encode = (obj: Lol): Uint8ArrayList => {
return encodeMessage(obj, Lol.codec())
}

export const decode = (buf: Uint8Array): Lol => {
export const decode = (buf: Uint8Array | Uint8ArrayList): Lol => {
return decodeMessage(buf, Lol.codec())
}
}
Expand All @@ -104,7 +110,7 @@ export interface Test {
}

export namespace Test {
export const codec = () => {
export const codec = (): Codec<Test> => {
return message<Test>({
6: { name: 'meh', codec: Lol.codec() },
3: { name: 'hello', codec: uint32 },
Expand All @@ -113,11 +119,11 @@ export namespace Test {
})
}

export const encode = (obj: Test): Uint8Array => {
export const encode = (obj: Test): Uint8ArrayList => {
return encodeMessage(obj, Test.codec())
}

export const decode = (buf: Uint8Array): Test => {
export const decode = (buf: Uint8Array | Uint8ArrayList): Test => {
return decodeMessage(buf, Test.codec())
}
}

0 comments on commit b6a9c18

Please sign in to comment.