2019-05-15 01:25:46 +03:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
import { Coder, Reader, Writer } from "./abstract-coder";
|
|
|
|
|
|
|
|
export class BooleanCoder extends Coder {
|
|
|
|
|
|
|
|
constructor(localName: string) {
|
|
|
|
super("bool", "bool", localName, false);
|
|
|
|
}
|
|
|
|
|
2020-11-23 08:59:44 +03:00
|
|
|
defaultValue(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-15 01:25:46 +03:00
|
|
|
encode(writer: Writer, value: boolean): number {
|
|
|
|
return writer.writeValue(value ? 1: 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
decode(reader: Reader): any {
|
|
|
|
return reader.coerce(this.type, !reader.readValue().isZero());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|