You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
671 B
29 lines
671 B
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)); |
|
} |
|
}
|
|
|