All files / ethers.js/src.ts/abi/coders bytes.ts

95.34% Statements 41/43
100% Branches 5/5
83.33% Functions 5/6
95.34% Lines 41/43

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1795x 1795x 1x 1x     1x 1x 1895x 1895x 1895x 1895x 1895x 1x 1x 2104x 2104x 1x 1x 1x 1x 1x 1x 1x 15x 15x 1x 1x 6x 6x 1x  
import { getBytesCopy, hexlify } from "../../utils/index.js";
 
import { Coder } from "./abstract-coder.js";
 
import type { Reader, Writer } from "./abstract-coder.js";
 
 
/**
 *  @_ignore
 */
export class DynamicBytesCoder extends Coder {
    constructor(type: string, localName: string) {
       super(type, type, localName, true);
    }
 
    defaultValue(): string {
        return "0x";
    }
 
    encode(writer: Writer, value: any): number {
        value = getBytesCopy(value);
        let length = writer.writeValue(value.length);
        length += writer.writeBytes(value);
        return length;
    }
 
    decode(reader: Reader): any {
        return reader.readBytes(reader.readIndex(), true);
    }
}
 
/**
 *  @_ignore
 */
export class BytesCoder extends DynamicBytesCoder {
    constructor(localName: string) {
        super("bytes", localName);
    }
 
    decode(reader: Reader): any {
        return hexlify(super.decode(reader));
    }
}