deukpack 1.0.1 → 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.
- package/dist/csharp/DeukPackSerializer.cs +256 -0
- package/dist/csharp/DeukPackThriftCompat.cs +147 -0
- package/dist/csharp/DpBinaryProtocol.cs +579 -0
- package/dist/csharp/DpJsonProtocol.cs +432 -0
- package/dist/csharp/DpProtocolCore.cs +314 -0
- package/dist/csharp/DpProtocolUtil.cs +51 -0
- package/dist/csharp/TBinaryProtocol.cs +227 -0
- package/dist/csharp/UnityCompatibleGenerator.cs +597 -0
- package/package.json +1 -1
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeukPackSerializer — 직렬화 헬퍼. DpProtocolLibrary 모듈화.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
using System;
|
|
6
|
+
using System.Collections.Generic;
|
|
7
|
+
using System.Linq;
|
|
8
|
+
using System.Reflection;
|
|
9
|
+
|
|
10
|
+
namespace DeukPack.Protocol
|
|
11
|
+
{
|
|
12
|
+
/// <summary>
|
|
13
|
+
/// DeukPack serialization helper - modularized to reduce code duplication
|
|
14
|
+
/// Recursive serialization support for nested structures
|
|
15
|
+
/// </summary>
|
|
16
|
+
public static class DeukPackSerializer
|
|
17
|
+
{
|
|
18
|
+
/// <summary>
|
|
19
|
+
/// Write a value recursively based on its type
|
|
20
|
+
/// </summary>
|
|
21
|
+
public static void WriteValue(DpProtocol oprot, DpWireType type, object value)
|
|
22
|
+
{
|
|
23
|
+
if (value == null)
|
|
24
|
+
return;
|
|
25
|
+
|
|
26
|
+
switch (type)
|
|
27
|
+
{
|
|
28
|
+
case DpWireType.Bool:
|
|
29
|
+
oprot.WriteBool((bool)value);
|
|
30
|
+
break;
|
|
31
|
+
case DpWireType.Byte:
|
|
32
|
+
oprot.WriteByte((byte)value);
|
|
33
|
+
break;
|
|
34
|
+
case DpWireType.I16:
|
|
35
|
+
oprot.WriteI16(value is short s16 ? s16 : Convert.ToInt16(value));
|
|
36
|
+
break;
|
|
37
|
+
case DpWireType.I32:
|
|
38
|
+
oprot.WriteI32(value is int i32 ? i32 : Convert.ToInt32(value));
|
|
39
|
+
break;
|
|
40
|
+
case DpWireType.I64:
|
|
41
|
+
oprot.WriteI64(value is long i64 ? i64 : Convert.ToInt64(value));
|
|
42
|
+
break;
|
|
43
|
+
case DpWireType.Double:
|
|
44
|
+
oprot.WriteDouble((double)value);
|
|
45
|
+
break;
|
|
46
|
+
case DpWireType.String:
|
|
47
|
+
if (value is byte[] bytes)
|
|
48
|
+
oprot.WriteBinary(bytes);
|
|
49
|
+
else
|
|
50
|
+
oprot.WriteString((string)value);
|
|
51
|
+
break;
|
|
52
|
+
case DpWireType.Struct:
|
|
53
|
+
if (value is IDpSerializable serializable)
|
|
54
|
+
serializable.Write(oprot);
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
if (value is IDpSerializable serializableValue)
|
|
58
|
+
serializableValue.Write(oprot);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/// <summary>
|
|
64
|
+
/// Read a value recursively based on its type
|
|
65
|
+
/// </summary>
|
|
66
|
+
public static object ReadValue(DpProtocol iprot, DpWireType type, Type targetType = null)
|
|
67
|
+
{
|
|
68
|
+
switch (type)
|
|
69
|
+
{
|
|
70
|
+
case DpWireType.Bool:
|
|
71
|
+
return iprot.ReadBool();
|
|
72
|
+
case DpWireType.Byte:
|
|
73
|
+
return iprot.ReadByte();
|
|
74
|
+
case DpWireType.I16:
|
|
75
|
+
{
|
|
76
|
+
short v = iprot.ReadI16();
|
|
77
|
+
return (targetType != null && targetType.IsEnum) ? Enum.ToObject(targetType, v) : (object)v;
|
|
78
|
+
}
|
|
79
|
+
case DpWireType.I32:
|
|
80
|
+
{
|
|
81
|
+
int v = iprot.ReadI32();
|
|
82
|
+
return (targetType != null && targetType.IsEnum) ? Enum.ToObject(targetType, v) : (object)v;
|
|
83
|
+
}
|
|
84
|
+
case DpWireType.I64:
|
|
85
|
+
{
|
|
86
|
+
long v = iprot.ReadI64();
|
|
87
|
+
return (targetType != null && targetType.IsEnum) ? Enum.ToObject(targetType, v) : (object)v;
|
|
88
|
+
}
|
|
89
|
+
case DpWireType.Double:
|
|
90
|
+
return iprot.ReadDouble();
|
|
91
|
+
case DpWireType.String:
|
|
92
|
+
if (targetType == typeof(string))
|
|
93
|
+
return iprot.ReadString();
|
|
94
|
+
return iprot.ReadBinary();
|
|
95
|
+
case DpWireType.Struct:
|
|
96
|
+
if (targetType != null)
|
|
97
|
+
{
|
|
98
|
+
var instance = Activator.CreateInstance(targetType);
|
|
99
|
+
if (instance is IDpSerializable serializable)
|
|
100
|
+
{
|
|
101
|
+
serializable.Read(iprot);
|
|
102
|
+
return instance;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
default:
|
|
107
|
+
if (targetType != null)
|
|
108
|
+
{
|
|
109
|
+
var instance = Activator.CreateInstance(targetType);
|
|
110
|
+
if (instance is IDpSerializable serializable)
|
|
111
|
+
{
|
|
112
|
+
serializable.Read(iprot);
|
|
113
|
+
return instance;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/// <summary>
|
|
121
|
+
/// Write a list recursively
|
|
122
|
+
/// </summary>
|
|
123
|
+
public static void WriteList<T>(DpProtocol oprot, DpWireType elementType, IEnumerable<T> list)
|
|
124
|
+
{
|
|
125
|
+
var count = list is ICollection<T> collection ? collection.Count : list.Count();
|
|
126
|
+
oprot.WriteListBegin(new DpList { ElementType = elementType, Count = count });
|
|
127
|
+
foreach (var item in list)
|
|
128
|
+
{
|
|
129
|
+
WriteValue(oprot, elementType, item);
|
|
130
|
+
}
|
|
131
|
+
oprot.WriteListEnd();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/// <summary>
|
|
135
|
+
/// Read a list recursively
|
|
136
|
+
/// </summary>
|
|
137
|
+
public static List<T> ReadList<T>(DpProtocol iprot, DpWireType elementType, Func<DpProtocol, T> reader = null)
|
|
138
|
+
{
|
|
139
|
+
var listInfo = iprot.ReadListBegin();
|
|
140
|
+
var list = new List<T>(listInfo.Count);
|
|
141
|
+
for (int i = 0; i < listInfo.Count; i++)
|
|
142
|
+
{
|
|
143
|
+
if (reader != null)
|
|
144
|
+
{
|
|
145
|
+
list.Add(reader(iprot));
|
|
146
|
+
}
|
|
147
|
+
else
|
|
148
|
+
{
|
|
149
|
+
var value = ReadValue(iprot, elementType, typeof(T));
|
|
150
|
+
if (value is T item)
|
|
151
|
+
{
|
|
152
|
+
list.Add(item);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
iprot.ReadListEnd();
|
|
157
|
+
return list;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/// <summary>
|
|
161
|
+
/// Write a set recursively
|
|
162
|
+
/// </summary>
|
|
163
|
+
public static void WriteSet<T>(DpProtocol oprot, DpWireType elementType, IEnumerable<T> set)
|
|
164
|
+
{
|
|
165
|
+
var count = set is ICollection<T> collection ? collection.Count : set.Count();
|
|
166
|
+
oprot.WriteSetBegin(new DpSet { ElementType = elementType, Count = count });
|
|
167
|
+
foreach (var item in set)
|
|
168
|
+
{
|
|
169
|
+
WriteValue(oprot, elementType, item);
|
|
170
|
+
}
|
|
171
|
+
oprot.WriteSetEnd();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/// <summary>
|
|
175
|
+
/// Read a set recursively
|
|
176
|
+
/// </summary>
|
|
177
|
+
public static HashSet<T> ReadSet<T>(DpProtocol iprot, DpWireType elementType, Func<DpProtocol, T> reader = null)
|
|
178
|
+
{
|
|
179
|
+
var setInfo = iprot.ReadSetBegin();
|
|
180
|
+
var set = new HashSet<T>();
|
|
181
|
+
for (int i = 0; i < setInfo.Count; i++)
|
|
182
|
+
{
|
|
183
|
+
if (reader != null)
|
|
184
|
+
{
|
|
185
|
+
set.Add(reader(iprot));
|
|
186
|
+
}
|
|
187
|
+
else
|
|
188
|
+
{
|
|
189
|
+
var value = ReadValue(iprot, elementType, typeof(T));
|
|
190
|
+
if (value is T item)
|
|
191
|
+
{
|
|
192
|
+
set.Add(item);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
iprot.ReadSetEnd();
|
|
197
|
+
return set;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/// <summary>
|
|
201
|
+
/// Write a map recursively
|
|
202
|
+
/// </summary>
|
|
203
|
+
public static void WriteMap<TKey, TValue>(DpProtocol oprot, DpWireType keyType, DpWireType valueType, IDictionary<TKey, TValue> map)
|
|
204
|
+
{
|
|
205
|
+
oprot.WriteMapBegin(new DpDict { KeyType = keyType, ValueType = valueType, Count = map.Count });
|
|
206
|
+
foreach (var kvp in map)
|
|
207
|
+
{
|
|
208
|
+
WriteValue(oprot, keyType, kvp.Key);
|
|
209
|
+
WriteValue(oprot, valueType, kvp.Value);
|
|
210
|
+
}
|
|
211
|
+
oprot.WriteMapEnd();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/// <summary>
|
|
215
|
+
/// Read a map recursively
|
|
216
|
+
/// </summary>
|
|
217
|
+
public static Dictionary<TKey, TValue> ReadMap<TKey, TValue>(
|
|
218
|
+
DpProtocol iprot,
|
|
219
|
+
DpWireType keyType,
|
|
220
|
+
DpWireType valueType,
|
|
221
|
+
Func<DpProtocol, TKey> keyReader = null,
|
|
222
|
+
Func<DpProtocol, TValue> valueReader = null)
|
|
223
|
+
{
|
|
224
|
+
var mapInfo = iprot.ReadMapBegin();
|
|
225
|
+
var map = new Dictionary<TKey, TValue>(mapInfo.Count);
|
|
226
|
+
for (int i = 0; i < mapInfo.Count; i++)
|
|
227
|
+
{
|
|
228
|
+
TKey key;
|
|
229
|
+
if (keyReader != null)
|
|
230
|
+
{
|
|
231
|
+
key = keyReader(iprot);
|
|
232
|
+
}
|
|
233
|
+
else
|
|
234
|
+
{
|
|
235
|
+
var keyValue = ReadValue(iprot, keyType, typeof(TKey));
|
|
236
|
+
key = keyValue is TKey k ? k : default(TKey);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
TValue value;
|
|
240
|
+
if (valueReader != null)
|
|
241
|
+
{
|
|
242
|
+
value = valueReader(iprot);
|
|
243
|
+
}
|
|
244
|
+
else
|
|
245
|
+
{
|
|
246
|
+
var valueObj = ReadValue(iprot, valueType, typeof(TValue));
|
|
247
|
+
value = valueObj is TValue v ? v : default(TValue);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
map[key] = value;
|
|
251
|
+
}
|
|
252
|
+
iprot.ReadMapEnd();
|
|
253
|
+
return map;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
@@ -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
|
+
}
|