WriteBytesFull() public method

This writes a 16-bit count and an array of bytes of that size to the stream.

public WriteBytesFull ( byte buffer ) : void
buffer byte Bytes to write.
return void
Ejemplo n.º 1
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(proxyId);
     writer.Write((short)packet.Compression);
     writer.Write(packet.Length);
     writer.WriteBytesFull(packet.Data);
 }
Ejemplo n.º 2
0
        internal bool SendFragmentBytes(byte[] bytes, int bytesToSend)
        {
            const int fragmentHeaderSize = 32;
            int       pos = 0;

            while (bytesToSend > 0)
            {
                int    diff   = Math.Min(bytesToSend, m_MaxPacketSize - fragmentHeaderSize);
                byte[] buffer = new byte[diff];
                Array.Copy(bytes, pos, buffer, 0, diff);

                s_FragmentWriter.StartMessage(MsgType.Fragment);
                s_FragmentWriter.Write((byte)0);
                s_FragmentWriter.WriteBytesFull(buffer);
                s_FragmentWriter.FinishMessage();
                SendWriter(s_FragmentWriter);

                pos         += diff;
                bytesToSend -= diff;
            }

            // send finish
            s_FragmentWriter.StartMessage(MsgType.Fragment);
            s_FragmentWriter.Write((byte)1);
            s_FragmentWriter.FinishMessage();
            SendWriter(s_FragmentWriter);

            return(true);
        }
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(this.netId);
     writer.WriteBytesFull(this.payload);
     writer.Write(this.teleport);
     writer.WritePackedUInt32((uint) this.time);
 }
Ejemplo n.º 4
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(this.netId);
     writer.Write(this.sceneId);
     writer.Write(this.position);
     writer.WriteBytesFull(this.payload);
 }
Ejemplo n.º 5
0
	public void WriteSetChunk(NetworkWriter nw)
	{
		if (updateMessageBytes) {

			NetworkWriter temp = new NetworkWriter();

			temp.Write(index.x);
			temp.Write(index.y);
			
			temp.Write(version);
			temp.Write(tileCount);
			
			for (int i = 0; i < VesselChunk.SIZE; i++) {
				
				for (int j = 0; j < VesselChunk.SIZE; j++) {
					
					VesselTile tile = TileAt(i, j);
					
					if (tile != null) {
						
						temp.Write(i);
						temp.Write(j);
						temp.Write((byte)tile.floor0);
						temp.Write((byte)tile.floor1);
						temp.Write((byte)tile.wallMask);
						temp.Write(tile.wallNode);
						
					}
				}
			}
			
			messageBytes = temp.ToArray();
			
			updateMessageBytes = false;
		}

		nw.WriteBytesFull(messageBytes);
	}
Ejemplo n.º 6
0
        internal bool SendFragmentBytes(byte[] bytes, int bytesToSend)
        {
            int num = 0;

            while (bytesToSend > 0)
            {
                int    num2  = Math.Min(bytesToSend, m_MaxPacketSize - 32);
                byte[] array = new byte[num2];
                Array.Copy(bytes, num, array, 0, num2);
                s_FragmentWriter.StartMessage(17);
                s_FragmentWriter.Write((byte)0);
                s_FragmentWriter.WriteBytesFull(array);
                s_FragmentWriter.FinishMessage();
                SendWriter(s_FragmentWriter);
                num         += num2;
                bytesToSend -= num2;
            }
            s_FragmentWriter.StartMessage(17);
            s_FragmentWriter.Write((byte)1);
            s_FragmentWriter.FinishMessage();
            SendWriter(s_FragmentWriter);
            return(true);
        }
Ejemplo n.º 7
0
    private IEnumerator SendWorld(int connectionID, World world)
    {
        {
            var writer = new NetworkWriter();

            writer.Write((byte) Type.Tilemap);
            writer.WriteBytesFull(world.tilemap);

            Send(connectionID, writer.AsArray());
        }

        {
            var writer = new NetworkWriter();

            writer.Write((byte) Type.Palette);
            
            for (int i = 0; i < 16; ++i) writer.Write((Color32) world.palette[i]);

            Send(connectionID, writer.AsArray());
        }

        {
            var writer = new NetworkWriter();

            writer.Write((byte) Type.Walls);
            writer.WriteBytesFull(world.walls.ToArray());

            Send(connectionID, writer.AsArray());
        }

        foreach (var avatar in world.avatars)
        {
            Send(connectionID, ReplicateAvatarMessage(avatar));

            if (avatar.id == connectionID)
            {
                Send(connectionID, GiveAvatarMessage(avatar));
            }
            else
            {
                Send(connectionID, AvatarInChunksMessages(world, avatar));
            }
        }

        for (int i = 0; i < maxTiles; ++i)
        {
            yield return new WaitForSeconds(0.125f);

            Send(connectionID, TileInChunksMessages(world, (byte) i));
        }
    }
Ejemplo n.º 8
0
    private byte[][] TileInChunksMessages(World world,
                                          byte tile,
                                          int size = 128)
    {
        int x = tile % 16;
        int y = tile / 16;

        Color[] colors = world.tileset.GetPixels(x * 32, y * 32, 32, 32);
        byte[] bytes = colors.Select(c => world.ColorToPalette(c, true)).ToArray();
        byte[] chunk;

        int offset = 0;

        var messages = new List<byte[]>();

        while (bytes.Any())
        {
            chunk = bytes.Take(size).ToArray();
            bytes = bytes.Skip(size).ToArray();

            var writer = new NetworkWriter();
            writer.Write((byte) Type.TileChunk);
            writer.Write(tile);
            writer.Write(offset);
            writer.WriteBytesFull(CrunchBytes(chunk));

            messages.Add(writer.AsArray());

            offset += size;
        }

        return messages.ToArray();
    }
Ejemplo n.º 9
0
    private byte[][] AvatarInChunksMessages(World world,
                                            World.Avatar avatar,
                                            int size = 128)
    {
        Color32[] colors = avatar.graphic.texture.GetPixels32();
        byte[] bytes = colors.Select(c => world.ColorToPalette(c, true)).ToArray();
        byte[] chunk;

        int offset = 0;

        var messages = new List<byte[]>();

        while (bytes.Any())
        {
            chunk = bytes.Take(size).ToArray();
            bytes = bytes.Skip(size).ToArray();

            var writer = new NetworkWriter();
            writer.Write((byte) Type.AvatarChunk);
            writer.Write(avatar.id);
            writer.Write(offset);
            writer.WriteBytesFull(CrunchBytes(chunk));

            messages.Add(writer.AsArray());

            offset += size;
        }

        return messages.ToArray();
    }
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(m_id);
     writer.Write(m_parentId);
     writer.Write(m_childId);
     writer.Write(m_position);
     writer.WriteBytesFull(m_payload);
 }