Typeberry by Fluffy Labs - v0.4.0
    Preparing search index...

    Class Decoder

    Primitives decoder for JAM codec.

    Index

    Properties

    source: Uint8Array

    Methods

    • Attach context to the decoder.

      The context object can be used to pass some "global" parameters down to custom decoders.

      Parameters

      • Optionalcontext: unknown

      Returns void

    • Decode a boolean discriminator.

      NOTE: this method will throw an exception in case the encoded byte is neither 0 nor 1.

      Returns boolean

    • Return the number of bytes read from the source (i.e. current offset within the source).

      Returns number

    • Finish decoding source object and make sure there is no data left.

      This method can be called when the entire object that was meant to be stored in the source is now fully decoded and we want to ensure that there is no extra bytes contained in the source.

      Returns void

    • Move the decoding cursor to given offset.

      Note the offset can actually be smaller than the current offset (i.e. one can go back).

      Parameters

      • newOffset: number

      Returns void

    • Decode a variable-length encoding of natural numbers (up to 2**32).

      NOTE: this method will panic in case a larger number is found in the source.

      Returns U32

    • Decode a single object from all of the source bytes.

      NOTE that if you need to decode multiple objects, it might be better to create a [Decoder] instance intstead of slicing the data.

      Type Parameters

      • T

      Parameters

      • decode: Decode<T>
      • source: Uint8Array<ArrayBufferLike> | BytesBlob
      • Optionalcontext: unknown

      Returns T

    • Decode a sequence of objects from all of the source bytes.

      Type Parameters

      • T

      Parameters

      • decode: Decode<T>
      • source: Uint8Array<ArrayBufferLike> | BytesBlob
      • Optionalcontext: unknown

      Returns T[]

    • Create a new [Decoder] instance given a raw array of bytes as a source.

      Parameters

      • source: Uint8Array
      • Optionalcontext: unknown

      Returns Decoder