as-scale-codec
Version:
AssemblyScript implementation of the SCALE codec used in the Parity Substrate framework
50 lines (45 loc) • 1.63 kB
text/typescript
// Copyright 2020 LimeChain Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @name Codec
* @description
* The base Codec interface. All supported types by the library must implement this interface.
* This interface represents the base functions required by every encoding/decoding of types
*/
export interface Codec {
/**
* @description Encodes the value as a Uint8Array as per the SCALE specification
*/
toU8a(): u8[];
/**
* @description The length of Uint8Array when the value is encoded
*/
encodedLength(): i32;
/**
* @description Non-static constructor method used to populate defined properties of the model
* @param bytes SCALE encoded bytes
* @param index index to start decoding the bytes from
*/
populateFromBytes(bytes: u8[], index: i32): void;
/**
* Checks if an instance is equal with other instance
* @param other other instance
*/
eq(other: Codec): bool;
/**
* Checks if an instance is not equal with other instance
* @param other other instance
*/
notEq(other: Codec): bool;
}