TG9six 03a642d635 first push
first push
2025-09-06 17:17:39 +04:00

51 lines
1017 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;
public class PacketWriter : Packet
{
public PacketWriter(int size) : base(size)
{
}
public void writeString(string s)
{
int length = s.Length;
writeInt(length);
for (int i =0; i < s.Length; i++)
{
payload[position++] = (byte)s[i];
}
}
public void writeFloat(float f)
{
byte[] data = BitConverter.GetBytes(f);
payload[position++] = data[0];
payload[position++] = data[1];
payload[position++] = data[2];
payload[position++] = data[3];
}
public void writeInt(int i)
{
byte[] data = BitConverter.GetBytes(i);
payload[position++] = (byte)(i >> 24);
payload[position++] = (byte)(i >> 16);
payload[position++] = (byte)(i >> 8);
payload[position++] = (byte)i;
}
public void writeFile(string file)
{
BinaryWriter writer = new BinaryWriter(File.Open( file + ".bytes", FileMode.Create));
writer.Write(payload);
writer.Close();
}
}