2019-05-14 18:25:46 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
import { toUtf8Bytes, toUtf8String } from "@ethersproject/strings";
|
|
|
|
|
|
|
|
import { Reader, Writer } from "./abstract-coder";
|
|
|
|
import { DynamicBytesCoder } from "./bytes";
|
|
|
|
|
|
|
|
export class StringCoder extends DynamicBytesCoder {
|
|
|
|
|
|
|
|
constructor(localName: string) {
|
|
|
|
super("string", localName);
|
|
|
|
}
|
|
|
|
|
2020-11-23 00:59:44 -05:00
|
|
|
defaultValue(): string {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2019-05-14 18:25:46 -04:00
|
|
|
encode(writer: Writer, value: any): number {
|
|
|
|
return super.encode(writer, toUtf8Bytes(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
decode(reader: Reader): any {
|
|
|
|
return toUtf8String(super.decode(reader));
|
|
|
|
}
|
|
|
|
}
|