Skip to content

Commit

Permalink
feat: BlockCodec methods are generic
Browse files Browse the repository at this point in the history
Adds support for generic types to the `encode` and `decode` methods on
the `BlockCodec` interface.
  • Loading branch information
tabcat authored and rvagg committed Jul 22, 2024
1 parent 38f1046 commit 2ee062e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/codecs/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import type { ArrayBufferView, ByteView } from '../block/interface.js'
/**
* IPLD encoder part of the codec.
*/
export interface BlockEncoder<Code extends number, T> {
export interface BlockEncoder<Code extends number, Universe> {
name: string
code: Code
encode(data: T): ByteView<T>
encode<T extends Universe>(data: T): ByteView<T>
}

/**
* IPLD decoder part of the codec.
*/
export interface BlockDecoder<Code extends number, T> {
export interface BlockDecoder<Code extends number, Universe> {
code: Code
decode(bytes: ByteView<T> | ArrayBufferView<T>): T
decode<T extends Universe>(bytes: ByteView<T> | ArrayBufferView<T>): T
}

/**
* An IPLD codec is a combination of both encoder and decoder.
*/
export interface BlockCodec<Code extends number, T> extends BlockEncoder<Code, T>, BlockDecoder<Code, T> {}
export interface BlockCodec<Code extends number, Universe> extends BlockEncoder<Code, Universe>, BlockDecoder<Code, Universe> {}

export type { ArrayBufferView, ByteView }

0 comments on commit 2ee062e

Please sign in to comment.