Skip to content
This repository was archived by the owner on Jan 11, 2022. It is now read-only.
This repository was archived by the owner on Jan 11, 2022. It is now read-only.

Improve type definitions for decode #78

@s1na

Description

@s1na

Thinking abstractly about decode I'd expect a function signature such as:

export function decode(input: Buffer): NestedBufferList

where NestedBufferList could be any nested composition of buffers and arrays such as Buffer, or Buffer[], or [Buffer, Buffer[]], etc. (haven't tried expressing this in TS).

Currently the decode method has the following definitions:

rlp/src/index.ts

Lines 60 to 63 in f06a96f

export function decode(input: Buffer, stream?: boolean): Buffer
export function decode(input: Buffer[], stream?: boolean): Buffer[]
export function decode(input: Input, stream?: boolean): Buffer[] | Buffer | Decoded
export function decode(input: Input, stream: boolean = false): Buffer[] | Buffer | Decoded {

  1. First definition takes Buffer and returns a Buffer. Not sure why, it could very well be that the decoding is a NestedBufferList. This was also the problem stated in Encoding and Decoding RLP lists when part of a buffer #77
  2. Second def. takes a Buffer[]. Is this to support decoding multiple serialized items simultaneously? the code doesn't seem to do that. I suggest we remove this
  3. The last two take Input as argument. I imagine this is for backwards-compatibility. I suggest we tighten the API and only accept a Buffer

On the stream flag: we could keep it, or add a new function decodeStreaming.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions