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

93.1% Statements 27/29
100% Branches 3/3
75% Functions 3/4
93.1% Lines 27/29

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 301x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1781x 1781x 1x 1x     1x 1x 1886x 1886x 1x 1x 2099x 2099x 1x  
import { toUtf8Bytes, toUtf8String } from "../../utils/utf8.js";
 
import { Typed } from "../typed.js";
import { DynamicBytesCoder } from "./bytes.js";
 
import type { Reader, Writer } from "./abstract-coder.js";
 
 
/**
 *  @_ignore
 */
export class StringCoder extends DynamicBytesCoder {
 
    constructor(localName: string) {
        super("string", localName);
    }
 
    defaultValue(): string {
        return "";
    }
 
    encode(writer: Writer, _value: string | Typed): number {
        return super.encode(writer, toUtf8Bytes(Typed.dereference(_value, "string")));
    }
 
    decode(reader: Reader): any {
        return toUtf8String(super.decode(reader));
    }
}