You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.0 KiB
66 lines
2.0 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BinarySerialize
|
|
{
|
|
class ConfigParse
|
|
{
|
|
|
|
public static uint GetUint(byte[] stream, int valuePos)
|
|
{
|
|
|
|
|
|
return (uint)((stream[valuePos] & 0xFF)
|
|
| ((stream[valuePos + 1] & 0xFF) << 8)
|
|
| ((stream[valuePos + 2] & 0xFF) << 16)
|
|
| ((stream[valuePos + 3] & 0xFF) << 24));
|
|
}
|
|
|
|
public static int GetInt(byte[] stream, int valuePos)
|
|
{
|
|
|
|
return (int)((stream[valuePos] & 0xFF)
|
|
| ((stream[valuePos + 1] & 0xFF) << 8)
|
|
| ((stream[valuePos + 2] & 0xFF) << 16)
|
|
| ((stream[valuePos + 3] & 0xFF) << 24));
|
|
}
|
|
|
|
|
|
public static long GetLong(byte[] stream, int valuePos)
|
|
{
|
|
return (long)((stream[valuePos] & 0xFF)
|
|
| ((stream[valuePos + 1] & 0xFF) << 8)
|
|
| ((stream[valuePos + 2] & 0xFF) << 16)
|
|
| ((stream[valuePos + 3] & 0xFF) << 24)
|
|
| ((stream[valuePos + 4] & 0xFF) << 32)
|
|
| ((stream[valuePos + 5] & 0xFF) << 40)
|
|
| ((stream[valuePos + 6] & 0xFF) << 48)
|
|
| ((stream[valuePos + 7] & 0xFF) << 56));
|
|
}
|
|
|
|
public static string GetString(byte[] stream, int valuePos, byte[] strStream)
|
|
{
|
|
int strlen = (int)((stream[valuePos] & 0xFF)
|
|
| ((stream[valuePos + 1] & 0xFF) << 8)
|
|
| ((stream[valuePos + 2] & 0xFF) << 16)
|
|
| ((stream[valuePos + 3] & 0xFF) << 24));
|
|
|
|
valuePos += 4;
|
|
int strpos = (int)((stream[valuePos] & 0xFF)
|
|
| ((stream[valuePos + 1] & 0xFF) << 8)
|
|
| ((stream[valuePos + 2] & 0xFF) << 16)
|
|
| ((stream[valuePos + 3] & 0xFF) << 24));
|
|
|
|
|
|
return Encoding.UTF8.GetString(strStream.Skip(strpos).Take(strlen).ToArray());
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|