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-benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"protobufjs": "^7.5.4",
"protons": "^8.0.0",
"protons-runtime": "^6.0.0",
"uint8arraylist": "^2.4.8"
"uint8arraylist": "^3.0.0"
},
"private": true
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable require-yield */

import { decodeMessage, encodeMessage, enumeration, MaxLengthError, message, streamMessage } from 'protons-runtime'
import type { Codec, DecodeOptions } from 'protons-runtime'
import type { Uint8ArrayList } from 'uint8arraylist'
Expand Down Expand Up @@ -78,7 +76,7 @@ export namespace Foo {
value: number
}

export function encode (obj: Partial<Foo>): Uint8Array {
export function encode (obj: Partial<Foo>): Uint8Array<ArrayBuffer> {
return encodeMessage(obj, Foo.codec())
}

Expand Down
6 changes: 3 additions & 3 deletions packages/protons-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@
"release": "aegir release"
},
"dependencies": {
"uint8-varint": "^2.0.4",
"uint8arraylist": "^2.4.8",
"uint8arrays": "^5.1.0"
"uint8-varint": "^3.0.0",
"uint8arraylist": "^3.0.0",
"uint8arrays": "^6.0.0"
},
"devDependencies": {
"aegir": "^48.0.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/protons-runtime/src/encode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createWriter } from './utils/writer.ts'
import type { Codec } from './codec.ts'

export function encodeMessage <T> (message: Partial<T>, codec: Pick<Codec<T>, 'encode'>): Uint8Array {
export function encodeMessage <T> (message: Partial<T>, codec: Pick<Codec<T>, 'encode'>): Uint8Array<ArrayBuffer> {
const w = createWriter()

codec.encode(message, w, {
Expand Down
4 changes: 2 additions & 2 deletions packages/protons-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export interface Writer {
/**
* Finishes the write operation
*/
finish(): Uint8Array
finish(): Uint8Array<ArrayBuffer>
}

export interface Reader {
Expand Down Expand Up @@ -250,7 +250,7 @@ export interface Reader {
/**
* Reads a sequence of bytes preceded by its length as a varint
*/
bytes(): Uint8Array
bytes(): Uint8Array<ArrayBuffer>

/**
* Reads a string preceded by its byte length as a varint
Expand Down
4 changes: 2 additions & 2 deletions packages/protons-runtime/src/utils/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { allocUnsafe } from 'uint8arrays/alloc'
/**
* A general purpose buffer pool
*/
export default function pool (size?: number): (size: number) => Uint8Array {
export default function pool (size?: number): (size: number) => Uint8Array<ArrayBuffer> {
const SIZE = size ?? 8192
const MAX = SIZE >>> 1
let slab: Uint8Array
let slab: Uint8Array<ArrayBuffer>
let offset = SIZE
return function poolAlloc (size: number) {
if (size < 1 || size > MAX) {
Expand Down
7 changes: 4 additions & 3 deletions packages/protons-runtime/src/utils/reader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { decodeUint8Array, encodingLength } from 'uint8-varint'
import { withArrayBuffer } from 'uint8arrays/with-array-buffer'
import { readFloatLE, readDoubleLE } from './float.ts'
import { LongBits } from './longbits.ts'
import * as utf8 from './utf8.ts'
Expand All @@ -21,7 +22,7 @@ function readFixed32End (buf: Uint8Array, end: number): number { // note that th
* Constructs a new reader instance using the specified buffer.
*/
export class Uint8ArrayReader implements Reader {
public buf: Uint8Array
public buf: Uint8Array<ArrayBuffer>
public pos: number
public len: number

Expand All @@ -31,7 +32,7 @@ export class Uint8ArrayReader implements Reader {
/**
* Read buffer
*/
this.buf = buffer
this.buf = withArrayBuffer(buffer)

/**
* Read buffer position
Expand Down Expand Up @@ -138,7 +139,7 @@ export class Uint8ArrayReader implements Reader {
/**
* Reads a sequence of bytes preceded by its length as a varint
*/
bytes (): Uint8Array {
bytes (): Uint8Array<ArrayBuffer> {
const length = this.uint32()
const start = this.pos
const end = this.pos + length
Expand Down
4 changes: 2 additions & 2 deletions packages/protons-runtime/src/utils/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const bufferPool = pool()
/**
* Allocates a buffer of the specified size
*/
function alloc (size: number): Uint8Array {
function alloc (size: number): Uint8Array<ArrayBuffer> {
if (globalThis.Buffer != null) {
return allocUnsafe(size)
}
Expand Down Expand Up @@ -393,7 +393,7 @@ class Uint8ArrayWriter implements Writer {
/**
* Finishes the write operation
*/
finish (): Uint8Array {
finish (): Uint8Array<ArrayBuffer> {
let head = this.head.next // skip noop
const buf = alloc(this.len)
let pos = 0
Expand Down
4 changes: 2 additions & 2 deletions packages/protons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"long": "^5.3.2",
"pbjs": "^0.0.14",
"protobufjs": "^7.5.4",
"uint8arraylist": "^2.4.8",
"uint8arrays": "^5.1.0"
"uint8arraylist": "^3.0.0",
"uint8arrays": "^6.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/protons/src/types/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ ${enforceOneOfDecoding === '' ? '' : `${enforceOneOfDecoding}\n`}
return _codec
}${this.formatStreamEvents(streamEvents)}

export function encode (obj: Partial<${this.pbType}>): Uint8Array {
export function encode (obj: Partial<${this.pbType}>): Uint8Array<ArrayBuffer> {
return encodeMessage(obj, ${this.pbType}.codec())
}

Expand Down
4 changes: 2 additions & 2 deletions packages/protons/test/fixtures/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export namespace Basic {
value: number
}

export function encode (obj: Partial<Basic>): Uint8Array {
export function encode (obj: Partial<Basic>): Uint8Array<ArrayBuffer> {
return encodeMessage(obj, Basic.codec())
}

Expand Down Expand Up @@ -166,7 +166,7 @@ export namespace Empty {
return _codec
}

export function encode (obj: Partial<Empty>): Uint8Array {
export function encode (obj: Partial<Empty>): Uint8Array<ArrayBuffer> {
return encodeMessage(obj, Empty.codec())
}

Expand Down
10 changes: 5 additions & 5 deletions packages/protons/test/fixtures/bitswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export namespace Message {
value: boolean
}

export function encode (obj: Partial<Entry>): Uint8Array {
export function encode (obj: Partial<Entry>): Uint8Array<ArrayBuffer> {
return encodeMessage(obj, Entry.codec())
}

Expand Down Expand Up @@ -355,7 +355,7 @@ export namespace Message {
value: boolean
}

export function encode (obj: Partial<Wantlist>): Uint8Array {
export function encode (obj: Partial<Wantlist>): Uint8Array<ArrayBuffer> {
return encodeMessage(obj, Wantlist.codec())
}

Expand Down Expand Up @@ -467,7 +467,7 @@ export namespace Message {
value: Uint8Array
}

export function encode (obj: Partial<Block>): Uint8Array {
export function encode (obj: Partial<Block>): Uint8Array<ArrayBuffer> {
return encodeMessage(obj, Block.codec())
}

Expand Down Expand Up @@ -595,7 +595,7 @@ export namespace Message {
value: Message.BlockPresenceType
}

export function encode (obj: Partial<BlockPresence>): Uint8Array {
export function encode (obj: Partial<BlockPresence>): Uint8Array<ArrayBuffer> {
return encodeMessage(obj, BlockPresence.codec())
}

Expand Down Expand Up @@ -871,7 +871,7 @@ export namespace Message {
value: number
}

export function encode (obj: Partial<Message>): Uint8Array {
export function encode (obj: Partial<Message>): Uint8Array<ArrayBuffer> {
return encodeMessage(obj, Message.codec())
}

Expand Down
4 changes: 2 additions & 2 deletions packages/protons/test/fixtures/circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export namespace CircuitRelay {
value: Uint8Array
}

export function encode (obj: Partial<Peer>): Uint8Array {
export function encode (obj: Partial<Peer>): Uint8Array<ArrayBuffer> {
return encodeMessage(obj, Peer.codec())
}

Expand Down Expand Up @@ -354,7 +354,7 @@ export namespace CircuitRelay {
value: CircuitRelay.Status
}

export function encode (obj: Partial<CircuitRelay>): Uint8Array {
export function encode (obj: Partial<CircuitRelay>): Uint8Array<ArrayBuffer> {
return encodeMessage(obj, CircuitRelay.codec())
}

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 @@ -113,7 +113,7 @@ export namespace CustomOptionNumber {
value: number
}

export function encode (obj: Partial<CustomOptionNumber$i64MapEntry>): Uint8Array {
export function encode (obj: Partial<CustomOptionNumber$i64MapEntry>): Uint8Array<ArrayBuffer> {
return encodeMessage(obj, CustomOptionNumber$i64MapEntry.codec())
}

Expand Down Expand Up @@ -391,7 +391,7 @@ export namespace CustomOptionNumber {
value: number
}

export function encode (obj: Partial<CustomOptionNumber>): Uint8Array {
export function encode (obj: Partial<CustomOptionNumber>): Uint8Array<ArrayBuffer> {
return encodeMessage(obj, CustomOptionNumber.codec())
}

Expand Down Expand Up @@ -515,7 +515,7 @@ export namespace CustomOptionString {
value: string
}

export function encode (obj: Partial<CustomOptionString$i64MapEntry>): Uint8Array {
export function encode (obj: Partial<CustomOptionString$i64MapEntry>): Uint8Array<ArrayBuffer> {
return encodeMessage(obj, CustomOptionString$i64MapEntry.codec())
}

Expand Down Expand Up @@ -793,7 +793,7 @@ export namespace CustomOptionString {
value: string
}

export function encode (obj: Partial<CustomOptionString>): Uint8Array {
export function encode (obj: Partial<CustomOptionString>): Uint8Array<ArrayBuffer> {
return encodeMessage(obj, CustomOptionString.codec())
}

Expand Down
Loading
Loading