예제 #1
0
    static void test_serialization()
    {
        Log("test_serialization");
        const int MaxPacketSize = 1024;
        var       serializer    = new TestSerializer();
        var       buffer        = new uint[MaxPacketSize / 4];
        var       writeStream   = new WriteStream();

        writeStream.Start(buffer);
        TestStruct input;

        input.bool_value = true;
        input.int_value  = -5;
        input.uint_value = 215;
        input.bits_value = 12345;
        serializer.WriteTestStruct(writeStream, ref input);
        writeStream.Finish();

        var packet     = writeStream.GetData();
        var readStream = new ReadStream();

        readStream.Start(packet);
        TestStruct output;

        serializer.ReadTestStruct(readStream, out output);
        readStream.Finish();

        AreEqual(input.bool_value, output.bool_value);
        AreEqual(input.int_value, output.int_value);
        AreEqual(input.uint_value, output.uint_value);
        AreEqual(input.bits_value, output.bits_value);
    }
  protected bool ReadClientsPacket(byte[] packet, bool[] areConnected, ulong[] userIds, string[] userNames) { //host only
    BeginSample("ReadServerInfoPacket");
    readStream.Start(packet);
    var result = true;

    try {
      serializer.ReadClientsPacket(readStream, areConnected, userIds, userNames);
    } catch (SerializeException) {
      Log("error: failed to read server info packet");
      result = false;
    }
    readStream.Finish();
    EndSample();

    return result;
  }
    bool ReadUpdateHeader(byte[] packet, out PacketHeader h)
    {
        Profiler.BeginSample("ReadStateUpdatePacketHeader");
        stream.Start(packet);
        var result = true;

        try {
            serializer.ReadUpdatePacketHeader(stream, out h);
        } catch (SerializeException) {
            Debug.Log("error: failed to read state update packet header");
            h.id         = 0;
            h.ack        = 0;
            h.ackBits    = 0;
            h.frame      = 0;
            h.resetId    = 0;
            h.timeOffset = 0.0f;
            result       = false;
        }
        stream.Finish();
        Profiler.EndSample();

        return(result);
    }