This repository was archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
This repository was archived by the owner on Jan 18, 2024. It is now read-only.
Create New ABI Serialization Deserialization Classes #38
Copy link
Copy link
Open
Description
Four or more classes
- ABIEncoder
- ABIDecoder
- ABIEncodeError
- ABIDecodeError
One or more interfaces
- ABISerializableObject
interface ABISerializableObject {
toABI?(encoder: ABIEncoder): void
toJSON(): any
equals(other: any): boolean
}class ABIDecoder {
private pos = 0
private data: DataView
private textDecoder = new TextDecoder('utf-8', {fatal: true})
/* declared references */
metadata: Record<string, any> = {}
/* constructor */
constructor(private array: Uint8Array)
/* functions */
canRead(bytes = 1): boolean
/* check not to exceed buffer */
private ensure(bytes: number)
setPosition(pos: number)
getPosition(): number
advance(bytes: number)
/** Read one byte. */
readByte(): number
/** Read floating point as JavaScript number, 32, 64 bits. Will extend later to 106 bits */
readFloat(byteWidth: number)
readVaruint32()
readVarint32()
/** will need to add readVarint64() later with BigInt **/
readArray(length: number)
readString()
decodeBinary(type: ABI.ResolvedType, decoder: ABIDecoder, ctx: DecodingContext): any
/** no decode object as we don't have proper types in eosjs (note: could be wrong **/
}export class ABIEncoder {
private pos = 0
private data: DataView
private array: Uint8Array
private textEncoder = new TextEncoder()
/** User declared metadata, can be used to pass info to instances when encoding. */
metadata: Record<string, any> = {}
/** constructor **/
constructor(private pageSize = 1024)
/** functions **
private ensure(bytes: number)
/** Write a single byte. */
writeByte(byte: number)
/** Write an array of bytes. */
writeArray(bytes: ArrayLike<number>)
/** need to extend this later to handle 106 bits **/
writeFloat(value: number, byteWidth: number)
writeVaruint32(v: number)
writeVarint32(v: number)
/** need to extend writeVarint64 with BigInt **/
writeString(v: string)
getData(): Uint8Array
getBytes(): BytesMetadata
Metadata
Assignees
Labels
No labels