2019-08-25 02:39:20 -04:00
|
|
|
"use strict";
|
|
|
|
import { arrayify, hexlify } from "@ethersproject/bytes";
|
|
|
|
import { Coder } from "./abstract-coder";
|
|
|
|
export class DynamicBytesCoder extends Coder {
|
|
|
|
constructor(type, localName) {
|
|
|
|
super(type, type, localName, true);
|
|
|
|
}
|
2020-11-23 03:43:28 -05:00
|
|
|
defaultValue() {
|
|
|
|
return "0x";
|
|
|
|
}
|
2019-08-25 02:39:20 -04:00
|
|
|
encode(writer, value) {
|
|
|
|
value = arrayify(value);
|
|
|
|
let length = writer.writeValue(value.length);
|
|
|
|
length += writer.writeBytes(value);
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
decode(reader) {
|
2020-09-07 19:55:52 -04:00
|
|
|
return reader.readBytes(reader.readValue().toNumber(), true);
|
2019-08-25 02:39:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
export class BytesCoder extends DynamicBytesCoder {
|
|
|
|
constructor(localName) {
|
|
|
|
super("bytes", localName);
|
|
|
|
}
|
|
|
|
decode(reader) {
|
|
|
|
return reader.coerce(this.name, hexlify(super.decode(reader)));
|
|
|
|
}
|
|
|
|
}
|
2020-07-13 08:03:56 -04:00
|
|
|
//# sourceMappingURL=bytes.js.map
|