示例#1
0
 public static void WriteByteArray(Stream fs, byte[] bytes)
 {
     if (bytes == null)
     {
         bytes = new byte[0];
     }
     FileSerializeHelper.WriteInt32(fs, bytes.Length);
     FileSerializeHelper.WriteBytes(fs, bytes);
 }
示例#2
0
 public static void WriteString(Stream fs, string str)
 {
     if (str == null)
     {
         str = string.Empty;
     }
     byte[] bytes = Encoding.Unicode.GetBytes(str);
     FileSerializeHelper.WriteInt32(fs, bytes.Length);
     FileSerializeHelper.WriteBytes(fs, bytes);
 }
示例#3
0
        public static byte[] ReadByteArray(Stream fs)
        {
            int bytesLength = FileSerializeHelper.ReadInt32(fs);

            if (bytesLength > 0)
            {
                return(FileSerializeHelper.ReadBytes(fs, bytesLength));
            }
            else
            {
                return(new byte[0]);
            }
        }
示例#4
0
        public static string ReadString(Stream fs)
        {
            int bytesLength = FileSerializeHelper.ReadInt32(fs);

            if (bytesLength > 0)
            {
                byte[] bytes = FileSerializeHelper.ReadBytes(fs, bytesLength);
                return(Encoding.Unicode.GetString(bytes, 0, bytesLength));
            }
            else
            {
                return(string.Empty);
            }
        }
示例#5
0
 public static int ReadInt32(Stream fs)
 {
     byte[] bytes = FileSerializeHelper.ReadBytes(fs, 4);
     return(BitConverter.ToInt32(bytes, 0));
 }
示例#6
0
 public static bool ReadBool(Stream fs)
 {
     byte[] bytes = FileSerializeHelper.ReadBytes(fs, 1);
     return(BitConverter.ToBoolean(bytes, 0));
 }
示例#7
0
 public static void WriteInt32(Stream fs, int val)
 {
     byte[] bytes = BitConverter.GetBytes(val);
     FileSerializeHelper.WriteBytes(fs, bytes);
 }