* A schema storing radians with 2 bytes of precision.
class RadiansSchema extends Schema < number > {
read ( input : ISerialInput ) : number {
const low = input . readByte ();
const high = input . readByte ();
const discrete = (high << 8 ) | low;
return (discrete / 65535 ) * Math . PI ;
write ( output : ISerialOutput , value : number ) : void {
// The value will be wrapped to be in range of [0, Math.PI)
const wrapped = ((value % Math . PI ) + Math . PI ) % Math . PI ;
// Quantizing the value to range of [0, 65535]
const discrete = Math . min (Math . floor ((wrapped / Math . PI ) * 65535 ) , 65535 );
const low = discrete & 0xff ;
const high = (discrete >> 8 ) & 0xff ;
measure ( _ : number , measurer : IMeasurer = new Measurer () ) : IMeasurer {
// The size of the data serialized by this schema
// doesn't depend on the actual value. It's always 2 bytes.
// Creating a singleton instance of the schema,
// since it has no configuration properties.
export const radians = new RadiansSchema ();