anchor.diff:              | _ -> failwith "bad packet type"
   
       member this.Send<'T> (msg : 'T, packetType) =
  -        match udp with
  -        | Udp.Client state -> state.sendStreamState
  -        | Udp.Server state -> state.sendStreamState
  -        |> SendStreamState.write msg (fun bytes startIndex size -> 
  +        let sendStreamState =
  +            match udp with
  +            | Udp.Client state -> state.sendStreamState
  +            | Udp.Server state -> state.sendStreamState
  +
  +        sendStreamState.Write (msg, fun bytes startIndex size -> 
               this.Send (bytes, startIndex, size, packetType)
           )
           
  
positive.code: open System.Collections.Generic
  open System.IO.Compression
  
  type SendStreamState =
      {
          sendStream :    ByteStream
      }
  
  module SendStreamState =
  
      let create () =
          {
              sendStream = new ByteStream (Array.zeroCreate <| 1024 * 1024)
          }
  
      let write (msg : 'T) f (state : SendStreamState) =
  
          match Network.lookup.TryGetValue typeof<'T> with
          | true, id ->
              let sendStream = state.sendStream
  
              let startIndex = int sendStream.Position
  
              let pickler = Network.FindTypeById id
              sendStream.Writer.WriteByte (byte id)
              pickler.serialize (msg :> obj) sendStream.Writer
  
              let size = int sendStream.Position - startIndex
  
              f state.sendStream.Raw startIndex (int size)
  
          | _ -> ()
  
  type ReceiveStreamState =
      {
          receiveStream : ByteStream
      }
  
  module ReceiveStreamState =
  
      let create () =
          {
              receiveStream = new ByteStream (Array.zeroCreate <| 1024 * 1024)
          }
  
      let rec read' (subscriptions : Event<obj> []) (state : ReceiveStreamState) =
          let reader = state.receiveStream.Reader
          let typeId = reader.ReadByte () |> int
  
          if subscriptions.Length > typeId && typeId >= 0 then
  
negative.code:         else
              failwith "This shouldn't happen."
  
      member __.Read subscriptions =
          bs.Position <- 0L
  
          while not bs.Reader.IsEndOfStream do
              read subscriptions
  
      member __.Write (bytes, offset, count) =
          bs.Write (bytes, offset, count)
  
      member this.Reset () =
          bs.SetLength 0L
  
      static member Create () =
          ReceiveStreamState (new ByteStream (Array.zeroCreate <| 1024 * 1024))
  
  [<AutoOpen>]
  module StateHelpers =
  