Closed uurha closed 2 years ago
Hi, thank you for your interest in my archive.
In fact, BitConverter serializes other data types into bytes, therefore, using BitConverter is not necessary to serialize bytes!
Try this below.
public static void Serialize(byte value, ref byte[] bytes)
{
byte[] _bytes = new byte[] {value};
bytes = bytes.Concat(_bytes).ToArray();
}
public static byte DeserializeByte(byte[] bytes, ref int offset)
{
byte _byte = bytes[offset];
offset += 1;
return _byte;
}
public static byte[] DeserializeByteArray(byte[] bytes, ref int offset)
{
int length = DeserializeInt(bytes, ref offset);
if (length > 0)
{
byte[] array = new byte[length];
for (int i = 0; i < array.Length; i++)
{
array[i] = DeserializeByte(bytes, ref offset);
}
return array;
}
return new byte[0];
}
Thanks. I'll come then I'll finish tests)
Only one change for Serialize(byte[])
public static void Serialize(byte[] value, ref byte[] bytes)
{
int length = value?.Length ?? 0;
if (length > 0)
{
Serialize(length, ref bytes);
JoinBytes(ref bytes, value);
}
else
{
Serialize(0, ref bytes);
}
}
Well tested and working good, thanks for your help) Should I close the issue?
Yes, please. Thanks for your advice, I'll update it to my serializer later on.
Yes, please. Thanks for your advice, I'll update it to my serializer later on.
I can make pull request from fork. Is that will be good?)
I can make pull request from fork. Is that will be good?)
Sure, :)
Hello, thanks for creating this serializer. It's very helpful, could you please help me with extending your serializer. I want to add serializing for byte[], but it gives me error about lenght of byte array, but I done this same as int[].