@@ -3,7 +3,8 @@ import { Data, Result } from 'effect'
33// NOTE: the bytes under the room protocol, after the estimate in
44// tools/mp-spike/wire.ts: unsigned integers as LEB128 varints, signed ones
55// zigzagged first, positions and other fractions as int16 fixed point,
6- // strings and byte runs prefixed with their length. A Reader that runs off
6+ // strings and byte runs prefixed with their length, and any other number
7+ // as a little-endian float64. A Reader that runs off
78// the end, or meets a malformed varint, throws a WireError, and `readAll`
89// turns that into a failed Result, so callers never see an exception.
910
@@ -42,6 +43,7 @@ export interface Writer {
4243 readonly i16 : ( value : number ) => void
4344 readonly fixed : ( value : number , scale : number ) => void
4445 readonly position : ( value : number ) => void
46+ readonly f64 : ( value : number ) => void
4547 readonly bool : ( value : boolean ) => void
4648 readonly bytes : ( value : Uint8Array ) => void
4749 readonly raw : ( value : Uint8Array ) => void
@@ -106,6 +108,11 @@ export const makeWriter = (capacity = 64): Writer => {
106108 i16,
107109 fixed : ( value , scale ) => i16 ( fixedOf ( value , scale ) ) ,
108110 position : value => i16 ( fixedOf ( value , POSITION_SCALE ) ) ,
111+ f64 : value => {
112+ const bytes = new Uint8Array ( 8 )
113+ new DataView ( bytes . buffer ) . setFloat64 ( 0 , value , true )
114+ raw ( bytes )
115+ } ,
109116 bool : value => u8 ( value ? 1 : 0 ) ,
110117 bytes : value => {
111118 varint ( value . length )
@@ -131,6 +138,7 @@ export interface Reader {
131138 readonly i16 : ( ) => number
132139 readonly fixed : ( scale : number ) => number
133140 readonly position : ( ) => number
141+ readonly f64 : ( ) => number
134142 readonly bool : ( ) => boolean
135143 readonly bytes : ( maxLength : number ) => Uint8Array
136144 readonly rest : ( ) => Uint8Array
@@ -197,6 +205,14 @@ export const makeReader = (bytes: Uint8Array): Reader => {
197205 i16,
198206 fixed : scale => i16 ( ) / scale ,
199207 position : ( ) => i16 ( ) / POSITION_SCALE ,
208+ f64 : ( ) => {
209+ const taken = take ( 8 )
210+ return new DataView (
211+ taken . buffer ,
212+ taken . byteOffset ,
213+ taken . byteLength ,
214+ ) . getFloat64 ( 0 , true )
215+ } ,
200216 bool : ( ) => u8 ( ) !== 0 ,
201217 bytes : maxLength => take ( lengthOf ( maxLength ) ) . slice ( ) ,
202218 rest : ( ) => take ( bytes . length - state . at ) . slice ( ) ,
0 commit comments