deukpack 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeukPack.Protocol compatibility: T* and Thrift* type names for existing generated code and add-in.
|
|
3
|
+
* New code should use Dp* types (DpProtocol, DpWireType, DpRecord, DpColumn, DpSchema, etc.).
|
|
4
|
+
* See docs/DEUKPACK_CORE_VS_APACHE_AND_OTHERS.md §5.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
using System;
|
|
8
|
+
|
|
9
|
+
namespace DeukPack.Protocol
|
|
10
|
+
{
|
|
11
|
+
#pragma warning disable CS0618 // Type or member is obsolete
|
|
12
|
+
|
|
13
|
+
[Obsolete("Use DpWireType")]
|
|
14
|
+
public enum TType
|
|
15
|
+
{
|
|
16
|
+
Stop = 0, Void = 1, Bool = 2, Byte = 3, Double = 4,
|
|
17
|
+
I16 = 6, I32 = 8, I64 = 10, String = 11, Struct = 12, Map = 13, Set = 14, List = 15
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
[Obsolete("Use DpProtocol")]
|
|
21
|
+
public interface TProtocol : DpProtocol { }
|
|
22
|
+
|
|
23
|
+
[Obsolete("Use DpRecord")]
|
|
24
|
+
public struct TStruct
|
|
25
|
+
{
|
|
26
|
+
public string Name;
|
|
27
|
+
public TStruct(string name) { Name = name; }
|
|
28
|
+
public static implicit operator TStruct(DpRecord r) => new TStruct(r.Name);
|
|
29
|
+
public static implicit operator DpRecord(TStruct t) => new DpRecord(t.Name);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
[Obsolete("Use DpColumn")]
|
|
33
|
+
public struct TField
|
|
34
|
+
{
|
|
35
|
+
public string Name;
|
|
36
|
+
public TType Type;
|
|
37
|
+
public short ID;
|
|
38
|
+
public TField(string name, TType type, short id) { Name = name; Type = type; ID = id; }
|
|
39
|
+
public static implicit operator TField(DpColumn c) => new TField(c.Name, (TType)(int)c.Type, c.ID);
|
|
40
|
+
public static implicit operator DpColumn(TField t) => new DpColumn(t.Name, (DpWireType)(int)t.Type, t.ID);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
[Obsolete("Use DpList")]
|
|
44
|
+
public struct TList
|
|
45
|
+
{
|
|
46
|
+
public TType ElementType;
|
|
47
|
+
public int Count;
|
|
48
|
+
public static implicit operator TList(DpList l) => new TList { ElementType = (TType)(int)l.ElementType, Count = l.Count };
|
|
49
|
+
public static implicit operator DpList(TList t) => new DpList { ElementType = (DpWireType)(int)t.ElementType, Count = t.Count };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
[Obsolete("Use DpSet")]
|
|
53
|
+
public struct TSet
|
|
54
|
+
{
|
|
55
|
+
public TType ElementType;
|
|
56
|
+
public int Count;
|
|
57
|
+
public static implicit operator TSet(DpSet s) => new TSet { ElementType = (TType)(int)s.ElementType, Count = s.Count };
|
|
58
|
+
public static implicit operator DpSet(TSet t) => new DpSet { ElementType = (DpWireType)(int)t.ElementType, Count = t.Count };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
[Obsolete("Use DpDict")]
|
|
62
|
+
public struct TMap
|
|
63
|
+
{
|
|
64
|
+
public TType KeyType;
|
|
65
|
+
public TType ValueType;
|
|
66
|
+
public int Count;
|
|
67
|
+
public static implicit operator TMap(DpDict d) => new TMap { KeyType = (TType)(int)d.KeyType, ValueType = (TType)(int)d.ValueType, Count = d.Count };
|
|
68
|
+
public static implicit operator DpDict(TMap t) => new DpDict { KeyType = (DpWireType)(int)t.KeyType, ValueType = (DpWireType)(int)t.ValueType, Count = t.Count };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
[Obsolete("Use DpProtocolUtil")]
|
|
72
|
+
public static class TProtocolUtil
|
|
73
|
+
{
|
|
74
|
+
public static void Skip(TProtocol prot, TType type) => DpProtocolUtil.Skip(prot, (DpWireType)(int)type);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
[Obsolete("Use DpSchemaType")]
|
|
78
|
+
public enum ThriftType
|
|
79
|
+
{
|
|
80
|
+
Bool, Byte, I16, I32, I64, Double, String, Binary, Struct, Enum, List, Set, Map
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
[Obsolete("Use DpDefinitionKind")]
|
|
84
|
+
public enum ThriftSchemaType
|
|
85
|
+
{
|
|
86
|
+
Struct, Enum, Typedef, Constant
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
[Obsolete("Use DpFieldSchema")]
|
|
90
|
+
public class ThriftFieldSchema
|
|
91
|
+
{
|
|
92
|
+
public int Id { get; set; }
|
|
93
|
+
public int Order { get; set; }
|
|
94
|
+
public string Name { get; set; }
|
|
95
|
+
public ThriftType Type { get; set; }
|
|
96
|
+
public string TypeName { get; set; }
|
|
97
|
+
public bool Required { get; set; }
|
|
98
|
+
public object DefaultValue { get; set; }
|
|
99
|
+
public string DocComment { get; set; }
|
|
100
|
+
public System.Collections.Generic.Dictionary<string, string> Annotations { get; set; }
|
|
101
|
+
public DpFieldSchema ToDpFieldSchema() => new DpFieldSchema
|
|
102
|
+
{
|
|
103
|
+
Id = Id, Order = Order, Name = Name, Type = (DpSchemaType)(int)Type, TypeName = TypeName,
|
|
104
|
+
Required = Required, DefaultValue = DefaultValue, DocComment = DocComment, Annotations = Annotations
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
[Obsolete("Use DpSchema")]
|
|
109
|
+
public class ThriftSchema
|
|
110
|
+
{
|
|
111
|
+
public string Name { get; set; }
|
|
112
|
+
public ThriftSchemaType Type { get; set; }
|
|
113
|
+
public System.Collections.Generic.Dictionary<int, ThriftFieldSchema> Fields { get; set; }
|
|
114
|
+
public string DocComment { get; set; }
|
|
115
|
+
public System.Collections.Generic.Dictionary<string, string> Annotations { get; set; }
|
|
116
|
+
public DpSchema ToDpSchema()
|
|
117
|
+
{
|
|
118
|
+
var fs = new System.Collections.Generic.Dictionary<int, DpFieldSchema>();
|
|
119
|
+
if (Fields != null)
|
|
120
|
+
foreach (var kv in Fields)
|
|
121
|
+
fs[kv.Key] = kv.Value.ToDpFieldSchema();
|
|
122
|
+
return new DpSchema
|
|
123
|
+
{
|
|
124
|
+
Name = Name,
|
|
125
|
+
Type = (DpDefinitionKind)(int)Type,
|
|
126
|
+
Fields = fs,
|
|
127
|
+
DocComment = DocComment,
|
|
128
|
+
Annotations = Annotations
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
[Obsolete("Use DpTypeNames")]
|
|
134
|
+
public static class ThriftProtocolTypeNames
|
|
135
|
+
{
|
|
136
|
+
public static string ToProtocolName(TType t) => DpTypeNames.ToProtocolName((DpWireType)(int)t);
|
|
137
|
+
public static DpWireType FromProtocolName(string dt) => DpTypeNames.FromProtocolName(dt);
|
|
138
|
+
public static bool IsContainerType(TType t) => DpTypeNames.IsContainerType((DpWireType)(int)t);
|
|
139
|
+
public static DpWireType FromSchemaTypeName(string name) => DpTypeNames.FromSchemaTypeName(name);
|
|
140
|
+
public static string StripOuterGeneric(string typeName) => DpTypeNames.StripOuterGeneric(typeName);
|
|
141
|
+
public static string SchemaFieldToDataType(ThriftFieldSchema f) => f == null ? "string" : DpTypeNames.SchemaFieldToDataType(f.ToDpFieldSchema());
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// TExcelProtocol moved to DeukPack.ExcelProtocol DLL (DpExcelCompat.cs)
|
|
145
|
+
|
|
146
|
+
#pragma warning restore CS0618
|
|
147
|
+
}
|
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unity-Compatible C# Generator for DeukPack
|
|
3
|
+
* Unity DLL 호환성을 위한 C# 코드 생성기
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
using System;
|
|
7
|
+
using System.Collections.Generic;
|
|
8
|
+
using System.Text;
|
|
9
|
+
using System.IO;
|
|
10
|
+
|
|
11
|
+
namespace DeukPack.Unity
|
|
12
|
+
{
|
|
13
|
+
/// <summary>
|
|
14
|
+
/// Unity 호환 Thrift 프로토콜 라이브러리
|
|
15
|
+
/// Unity 2020.3+ 지원
|
|
16
|
+
/// </summary>
|
|
17
|
+
public enum TType : byte
|
|
18
|
+
{
|
|
19
|
+
Stop = 0,
|
|
20
|
+
Void = 1,
|
|
21
|
+
Bool = 2,
|
|
22
|
+
Byte = 3,
|
|
23
|
+
Double = 4,
|
|
24
|
+
I16 = 6,
|
|
25
|
+
I32 = 8,
|
|
26
|
+
I64 = 10,
|
|
27
|
+
String = 11,
|
|
28
|
+
Struct = 12,
|
|
29
|
+
Map = 13,
|
|
30
|
+
Set = 14,
|
|
31
|
+
List = 15
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// <summary>
|
|
35
|
+
/// Unity 호환 Thrift 메시지 타입
|
|
36
|
+
/// </summary>
|
|
37
|
+
public enum TMessageType : byte
|
|
38
|
+
{
|
|
39
|
+
Call = 1,
|
|
40
|
+
Reply = 2,
|
|
41
|
+
Exception = 3,
|
|
42
|
+
Oneway = 4
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/// <summary>
|
|
46
|
+
/// Unity 호환 Thrift 구조체 정보
|
|
47
|
+
/// </summary>
|
|
48
|
+
[System.Serializable]
|
|
49
|
+
public struct TStruct
|
|
50
|
+
{
|
|
51
|
+
public string Name;
|
|
52
|
+
|
|
53
|
+
public TStruct(string name)
|
|
54
|
+
{
|
|
55
|
+
Name = name;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// <summary>
|
|
60
|
+
/// Unity 호환 Thrift 필드 정보
|
|
61
|
+
/// </summary>
|
|
62
|
+
[System.Serializable]
|
|
63
|
+
public struct TField
|
|
64
|
+
{
|
|
65
|
+
public string Name;
|
|
66
|
+
public TType Type;
|
|
67
|
+
public short ID;
|
|
68
|
+
|
|
69
|
+
public TField(string name, TType type, short id)
|
|
70
|
+
{
|
|
71
|
+
Name = name;
|
|
72
|
+
Type = type;
|
|
73
|
+
ID = id;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/// <summary>
|
|
78
|
+
/// Unity 호환 Thrift 리스트 정보
|
|
79
|
+
/// </summary>
|
|
80
|
+
[System.Serializable]
|
|
81
|
+
public struct TList
|
|
82
|
+
{
|
|
83
|
+
public TType ElementType;
|
|
84
|
+
public int Count;
|
|
85
|
+
|
|
86
|
+
public TList(TType elementType, int count)
|
|
87
|
+
{
|
|
88
|
+
ElementType = elementType;
|
|
89
|
+
Count = count;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// <summary>
|
|
94
|
+
/// Unity 호환 Thrift 셋 정보
|
|
95
|
+
/// </summary>
|
|
96
|
+
[System.Serializable]
|
|
97
|
+
public struct TSet
|
|
98
|
+
{
|
|
99
|
+
public TType ElementType;
|
|
100
|
+
public int Count;
|
|
101
|
+
|
|
102
|
+
public TSet(TType elementType, int count)
|
|
103
|
+
{
|
|
104
|
+
ElementType = elementType;
|
|
105
|
+
Count = count;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/// <summary>
|
|
110
|
+
/// Unity 호환 Thrift 맵 정보
|
|
111
|
+
/// </summary>
|
|
112
|
+
[System.Serializable]
|
|
113
|
+
public struct TMap
|
|
114
|
+
{
|
|
115
|
+
public TType KeyType;
|
|
116
|
+
public TType ValueType;
|
|
117
|
+
public int Count;
|
|
118
|
+
|
|
119
|
+
public TMap(TType keyType, TType valueType, int count)
|
|
120
|
+
{
|
|
121
|
+
KeyType = keyType;
|
|
122
|
+
ValueType = valueType;
|
|
123
|
+
Count = count;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/// <summary>
|
|
128
|
+
/// Unity 호환 Thrift 프로토콜 인터페이스
|
|
129
|
+
/// </summary>
|
|
130
|
+
public interface TProtocol
|
|
131
|
+
{
|
|
132
|
+
void WriteStructBegin(TStruct structBegin);
|
|
133
|
+
void WriteStructEnd();
|
|
134
|
+
void WriteFieldBegin(TField field);
|
|
135
|
+
void WriteFieldEnd();
|
|
136
|
+
void WriteFieldStop();
|
|
137
|
+
void WriteBool(bool b);
|
|
138
|
+
void WriteByte(byte b);
|
|
139
|
+
void WriteI16(short i16);
|
|
140
|
+
void WriteI32(int i32);
|
|
141
|
+
void WriteI64(long i64);
|
|
142
|
+
void WriteDouble(double d);
|
|
143
|
+
void WriteString(string s);
|
|
144
|
+
void WriteBinary(byte[] b);
|
|
145
|
+
void WriteListBegin(TList list);
|
|
146
|
+
void WriteListEnd();
|
|
147
|
+
void WriteSetBegin(TSet set);
|
|
148
|
+
void WriteSetEnd();
|
|
149
|
+
void WriteMapBegin(TMap map);
|
|
150
|
+
void WriteMapEnd();
|
|
151
|
+
|
|
152
|
+
TStruct ReadStructBegin();
|
|
153
|
+
void ReadStructEnd();
|
|
154
|
+
TField ReadFieldBegin();
|
|
155
|
+
void ReadFieldEnd();
|
|
156
|
+
bool ReadBool();
|
|
157
|
+
byte ReadByte();
|
|
158
|
+
short ReadI16();
|
|
159
|
+
int ReadI32();
|
|
160
|
+
long ReadI64();
|
|
161
|
+
double ReadDouble();
|
|
162
|
+
string ReadString();
|
|
163
|
+
byte[] ReadBinary();
|
|
164
|
+
TList ReadListBegin();
|
|
165
|
+
void ReadListEnd();
|
|
166
|
+
TSet ReadSetBegin();
|
|
167
|
+
void ReadSetEnd();
|
|
168
|
+
TMap ReadMapBegin();
|
|
169
|
+
void ReadMapEnd();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/// <summary>
|
|
173
|
+
/// Unity 호환 바이너리 프로토콜
|
|
174
|
+
/// Unity의 메모리 관리에 최적화
|
|
175
|
+
/// </summary>
|
|
176
|
+
public class TBinaryProtocol : TProtocol
|
|
177
|
+
{
|
|
178
|
+
private byte[] _buffer;
|
|
179
|
+
private int _offset;
|
|
180
|
+
private bool _strictRead;
|
|
181
|
+
private bool _strictWrite;
|
|
182
|
+
|
|
183
|
+
public TBinaryProtocol(byte[] buffer, bool strictRead = true, bool strictWrite = true)
|
|
184
|
+
{
|
|
185
|
+
_buffer = buffer;
|
|
186
|
+
_offset = 0;
|
|
187
|
+
_strictRead = strictRead;
|
|
188
|
+
_strictWrite = strictWrite;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
public void WriteStructBegin(TStruct structBegin)
|
|
192
|
+
{
|
|
193
|
+
// Binary protocol doesn't write struct names
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
public void WriteStructEnd()
|
|
197
|
+
{
|
|
198
|
+
// Binary protocol doesn't write struct end markers
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public void WriteFieldBegin(TField field)
|
|
202
|
+
{
|
|
203
|
+
WriteByte((byte)field.Type);
|
|
204
|
+
WriteI16(field.ID);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
public void WriteFieldEnd()
|
|
208
|
+
{
|
|
209
|
+
// Binary protocol doesn't write field end markers
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
public void WriteFieldStop()
|
|
213
|
+
{
|
|
214
|
+
WriteByte((byte)TType.Stop);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public void WriteBool(bool b)
|
|
218
|
+
{
|
|
219
|
+
WriteByte(b ? (byte)1 : (byte)0);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
public void WriteByte(byte b)
|
|
223
|
+
{
|
|
224
|
+
if (_offset >= _buffer.Length)
|
|
225
|
+
{
|
|
226
|
+
Array.Resize(ref _buffer, _buffer.Length * 2);
|
|
227
|
+
}
|
|
228
|
+
_buffer[_offset++] = b;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
public void WriteI16(short i16)
|
|
232
|
+
{
|
|
233
|
+
byte[] bytes = BitConverter.GetBytes(i16);
|
|
234
|
+
if (!BitConverter.IsLittleEndian)
|
|
235
|
+
{
|
|
236
|
+
Array.Reverse(bytes);
|
|
237
|
+
}
|
|
238
|
+
WriteBytes(bytes);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
public void WriteI32(int i32)
|
|
242
|
+
{
|
|
243
|
+
byte[] bytes = BitConverter.GetBytes(i32);
|
|
244
|
+
if (!BitConverter.IsLittleEndian)
|
|
245
|
+
{
|
|
246
|
+
Array.Reverse(bytes);
|
|
247
|
+
}
|
|
248
|
+
WriteBytes(bytes);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
public void WriteI64(long i64)
|
|
252
|
+
{
|
|
253
|
+
byte[] bytes = BitConverter.GetBytes(i64);
|
|
254
|
+
if (!BitConverter.IsLittleEndian)
|
|
255
|
+
{
|
|
256
|
+
Array.Reverse(bytes);
|
|
257
|
+
}
|
|
258
|
+
WriteBytes(bytes);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
public void WriteDouble(double d)
|
|
262
|
+
{
|
|
263
|
+
byte[] bytes = BitConverter.GetBytes(d);
|
|
264
|
+
if (!BitConverter.IsLittleEndian)
|
|
265
|
+
{
|
|
266
|
+
Array.Reverse(bytes);
|
|
267
|
+
}
|
|
268
|
+
WriteBytes(bytes);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
public void WriteString(string s)
|
|
272
|
+
{
|
|
273
|
+
byte[] bytes = Encoding.UTF8.GetBytes(s);
|
|
274
|
+
WriteI32(bytes.Length);
|
|
275
|
+
WriteBytes(bytes);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
public void WriteBinary(byte[] b)
|
|
279
|
+
{
|
|
280
|
+
WriteI32(b.Length);
|
|
281
|
+
WriteBytes(b);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
public void WriteListBegin(TList list)
|
|
285
|
+
{
|
|
286
|
+
WriteByte((byte)list.ElementType);
|
|
287
|
+
WriteI32(list.Count);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
public void WriteListEnd()
|
|
291
|
+
{
|
|
292
|
+
// Binary protocol doesn't write list end markers
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
public void WriteSetBegin(TSet set)
|
|
296
|
+
{
|
|
297
|
+
WriteByte((byte)set.ElementType);
|
|
298
|
+
WriteI32(set.Count);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
public void WriteSetEnd()
|
|
302
|
+
{
|
|
303
|
+
// Binary protocol doesn't write set end markers
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
public void WriteMapBegin(TMap map)
|
|
307
|
+
{
|
|
308
|
+
WriteByte((byte)map.KeyType);
|
|
309
|
+
WriteByte((byte)map.ValueType);
|
|
310
|
+
WriteI32(map.Count);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
public void WriteMapEnd()
|
|
314
|
+
{
|
|
315
|
+
// Binary protocol doesn't write map end markers
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
public TStruct ReadStructBegin()
|
|
319
|
+
{
|
|
320
|
+
return new TStruct();
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
public void ReadStructEnd()
|
|
324
|
+
{
|
|
325
|
+
// Binary protocol doesn't read struct end markers
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
public TField ReadFieldBegin()
|
|
329
|
+
{
|
|
330
|
+
byte type = ReadByte();
|
|
331
|
+
if (type == (byte)TType.Stop)
|
|
332
|
+
{
|
|
333
|
+
return new TField("", TType.Stop, 0);
|
|
334
|
+
}
|
|
335
|
+
short id = ReadI16();
|
|
336
|
+
return new TField("", (TType)type, id);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
public void ReadFieldEnd()
|
|
340
|
+
{
|
|
341
|
+
// Binary protocol doesn't read field end markers
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
public bool ReadBool()
|
|
345
|
+
{
|
|
346
|
+
return ReadByte() != 0;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
public byte ReadByte()
|
|
350
|
+
{
|
|
351
|
+
if (_offset >= _buffer.Length)
|
|
352
|
+
{
|
|
353
|
+
throw new EndOfStreamException();
|
|
354
|
+
}
|
|
355
|
+
return _buffer[_offset++];
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
public short ReadI16()
|
|
359
|
+
{
|
|
360
|
+
byte[] bytes = ReadBytes(2);
|
|
361
|
+
if (!BitConverter.IsLittleEndian)
|
|
362
|
+
{
|
|
363
|
+
Array.Reverse(bytes);
|
|
364
|
+
}
|
|
365
|
+
return BitConverter.ToInt16(bytes, 0);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
public int ReadI32()
|
|
369
|
+
{
|
|
370
|
+
byte[] bytes = ReadBytes(4);
|
|
371
|
+
if (!BitConverter.IsLittleEndian)
|
|
372
|
+
{
|
|
373
|
+
Array.Reverse(bytes);
|
|
374
|
+
}
|
|
375
|
+
return BitConverter.ToInt32(bytes, 0);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
public long ReadI64()
|
|
379
|
+
{
|
|
380
|
+
byte[] bytes = ReadBytes(8);
|
|
381
|
+
if (!BitConverter.IsLittleEndian)
|
|
382
|
+
{
|
|
383
|
+
Array.Reverse(bytes);
|
|
384
|
+
}
|
|
385
|
+
return BitConverter.ToInt64(bytes, 0);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
public double ReadDouble()
|
|
389
|
+
{
|
|
390
|
+
byte[] bytes = ReadBytes(8);
|
|
391
|
+
if (!BitConverter.IsLittleEndian)
|
|
392
|
+
{
|
|
393
|
+
Array.Reverse(bytes);
|
|
394
|
+
}
|
|
395
|
+
return BitConverter.ToDouble(bytes, 0);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
public string ReadString()
|
|
399
|
+
{
|
|
400
|
+
int length = ReadI32();
|
|
401
|
+
byte[] bytes = ReadBytes(length);
|
|
402
|
+
return Encoding.UTF8.GetString(bytes);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
public byte[] ReadBinary()
|
|
406
|
+
{
|
|
407
|
+
int length = ReadI32();
|
|
408
|
+
return ReadBytes(length);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
public TList ReadListBegin()
|
|
412
|
+
{
|
|
413
|
+
byte elementType = ReadByte();
|
|
414
|
+
int count = ReadI32();
|
|
415
|
+
return new TList((TType)elementType, count);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
public void ReadListEnd()
|
|
419
|
+
{
|
|
420
|
+
// Binary protocol doesn't read list end markers
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
public TSet ReadSetBegin()
|
|
424
|
+
{
|
|
425
|
+
byte elementType = ReadByte();
|
|
426
|
+
int count = ReadI32();
|
|
427
|
+
return new TSet((TType)elementType, count);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
public void ReadSetEnd()
|
|
431
|
+
{
|
|
432
|
+
// Binary protocol doesn't read set end markers
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
public TMap ReadMapBegin()
|
|
436
|
+
{
|
|
437
|
+
byte keyType = ReadByte();
|
|
438
|
+
byte valueType = ReadByte();
|
|
439
|
+
int count = ReadI32();
|
|
440
|
+
return new TMap((TType)keyType, (TType)valueType, count);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
public void ReadMapEnd()
|
|
444
|
+
{
|
|
445
|
+
// Binary protocol doesn't read map end markers
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
private void WriteBytes(byte[] bytes)
|
|
449
|
+
{
|
|
450
|
+
if (_offset + bytes.Length > _buffer.Length)
|
|
451
|
+
{
|
|
452
|
+
Array.Resize(ref _buffer, Math.Max(_buffer.Length * 2, _offset + bytes.Length));
|
|
453
|
+
}
|
|
454
|
+
Array.Copy(bytes, 0, _buffer, _offset, bytes.Length);
|
|
455
|
+
_offset += bytes.Length;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
private byte[] ReadBytes(int count)
|
|
459
|
+
{
|
|
460
|
+
if (_offset + count > _buffer.Length)
|
|
461
|
+
{
|
|
462
|
+
throw new EndOfStreamException();
|
|
463
|
+
}
|
|
464
|
+
byte[] result = new byte[count];
|
|
465
|
+
Array.Copy(_buffer, _offset, result, 0, count);
|
|
466
|
+
_offset += count;
|
|
467
|
+
return result;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// Unity 호환성 메서드
|
|
471
|
+
public byte[] GetBuffer()
|
|
472
|
+
{
|
|
473
|
+
byte[] result = new byte[_offset];
|
|
474
|
+
Array.Copy(_buffer, 0, result, 0, _offset);
|
|
475
|
+
return result;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
public int GetOffset()
|
|
479
|
+
{
|
|
480
|
+
return _offset;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
public void SetOffset(int offset)
|
|
484
|
+
{
|
|
485
|
+
_offset = offset;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/// <summary>
|
|
490
|
+
/// Unity 호환 Thrift 프로토콜 유틸리티
|
|
491
|
+
/// </summary>
|
|
492
|
+
public static class TProtocolUtil
|
|
493
|
+
{
|
|
494
|
+
public static void Skip(TProtocol prot, TType type)
|
|
495
|
+
{
|
|
496
|
+
switch (type)
|
|
497
|
+
{
|
|
498
|
+
case TType.Bool:
|
|
499
|
+
prot.ReadBool();
|
|
500
|
+
break;
|
|
501
|
+
case TType.Byte:
|
|
502
|
+
prot.ReadByte();
|
|
503
|
+
break;
|
|
504
|
+
case TType.I16:
|
|
505
|
+
prot.ReadI16();
|
|
506
|
+
break;
|
|
507
|
+
case TType.I32:
|
|
508
|
+
prot.ReadI32();
|
|
509
|
+
break;
|
|
510
|
+
case TType.I64:
|
|
511
|
+
prot.ReadI64();
|
|
512
|
+
break;
|
|
513
|
+
case TType.Double:
|
|
514
|
+
prot.ReadDouble();
|
|
515
|
+
break;
|
|
516
|
+
case TType.String:
|
|
517
|
+
prot.ReadString();
|
|
518
|
+
break;
|
|
519
|
+
case TType.Binary:
|
|
520
|
+
prot.ReadBinary();
|
|
521
|
+
break;
|
|
522
|
+
case TType.List:
|
|
523
|
+
var list = prot.ReadListBegin();
|
|
524
|
+
for (int i = 0; i < list.Count; i++)
|
|
525
|
+
{
|
|
526
|
+
Skip(prot, list.ElementType);
|
|
527
|
+
}
|
|
528
|
+
prot.ReadListEnd();
|
|
529
|
+
break;
|
|
530
|
+
case TType.Set:
|
|
531
|
+
var set = prot.ReadSetBegin();
|
|
532
|
+
for (int i = 0; i < set.Count; i++)
|
|
533
|
+
{
|
|
534
|
+
Skip(prot, set.ElementType);
|
|
535
|
+
}
|
|
536
|
+
prot.ReadSetEnd();
|
|
537
|
+
break;
|
|
538
|
+
case TType.Map:
|
|
539
|
+
var map = prot.ReadMapBegin();
|
|
540
|
+
for (int i = 0; i < map.Count; i++)
|
|
541
|
+
{
|
|
542
|
+
Skip(prot, map.KeyType);
|
|
543
|
+
Skip(prot, map.ValueType);
|
|
544
|
+
}
|
|
545
|
+
prot.ReadMapEnd();
|
|
546
|
+
break;
|
|
547
|
+
case TType.Struct:
|
|
548
|
+
prot.ReadStructBegin();
|
|
549
|
+
while (true)
|
|
550
|
+
{
|
|
551
|
+
var field = prot.ReadFieldBegin();
|
|
552
|
+
if (field.Type == TType.Stop)
|
|
553
|
+
{
|
|
554
|
+
break;
|
|
555
|
+
}
|
|
556
|
+
Skip(prot, field.Type);
|
|
557
|
+
prot.ReadFieldEnd();
|
|
558
|
+
}
|
|
559
|
+
prot.ReadStructEnd();
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/// <summary>
|
|
566
|
+
/// Unity 호환 Thrift 직렬화 헬퍼
|
|
567
|
+
/// Unity의 메모리 관리에 최적화
|
|
568
|
+
/// </summary>
|
|
569
|
+
public static class ThriftSerializer
|
|
570
|
+
{
|
|
571
|
+
private static readonly byte[] _tempBuffer = new byte[1024 * 1024]; // 1MB temp buffer
|
|
572
|
+
|
|
573
|
+
public static byte[] Serialize<T>(T obj) where T : IThriftSerializable
|
|
574
|
+
{
|
|
575
|
+
var protocol = new TBinaryProtocol(_tempBuffer, true, true);
|
|
576
|
+
obj.Write(protocol);
|
|
577
|
+
return protocol.GetBuffer();
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
public static T Deserialize<T>(byte[] data) where T : IThriftSerializable, new()
|
|
581
|
+
{
|
|
582
|
+
var protocol = new TBinaryProtocol(data, true, true);
|
|
583
|
+
var obj = new T();
|
|
584
|
+
obj.Read(protocol);
|
|
585
|
+
return obj;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/// <summary>
|
|
590
|
+
/// Unity 호환 Thrift 직렬화 인터페이스
|
|
591
|
+
/// </summary>
|
|
592
|
+
public interface IThriftSerializable
|
|
593
|
+
{
|
|
594
|
+
void Write(TProtocol oprot);
|
|
595
|
+
void Read(TProtocol iprot);
|
|
596
|
+
}
|
|
597
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deukpack",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "DeukPack — multi-format IDL pipeline (.deuk native, Protobuf, OpenAPI, JSON Schema, CSV, Thrift). Protobuf-aligned wire; fast C#/C++/JS codegen, CLI. v1: no Excel/table editor workflow",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|