-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathstringBuffer.cs
More file actions
38 lines (35 loc) · 1.1 KB
/
Copy pathstringBuffer.cs
File metadata and controls
38 lines (35 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* File Name: stringBuffer.cs
*
* Description: 基本类型处理
* Author: lisiyu <576603306@qq.com>
* Create Date: 2017/10/25
*/
using System.Text;
namespace xbuffer
{
public class stringBuffer
{
public unsafe static string deserialize(byte[] buffer, ref uint offset)
{
fixed (byte* ptr = buffer)
{
uint byteCount = uintBuffer.deserialize(buffer, ref offset);
string value = Encoding.UTF8.GetString(buffer, (int)offset, (int)byteCount);
offset += byteCount;
return value;
}
}
public unsafe static void serialize(string value, XSteam steam)
{
var bytes = Encoding.UTF8.GetBytes(value);
uintBuffer.serialize((uint)bytes.Length, steam);
for (int i = 0; i < bytes.Length; i++)
{
steam.applySize(1);
steam.contents[steam.index_group][steam.index_cell] = bytes[i];
steam.index_cell += 1;
}
}
}
}