Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FieldMetadata.cs
Go to the documentation of this file.
1using System.Text;
2
4
5internal sealed class FieldMetadata
6{
7 private readonly string name;
8
9 private readonly int nameSize;
10
11 private readonly EventFieldTags tags;
12
13 private readonly byte[] custom;
14
15 private readonly ushort fixedCount;
16
17 private byte inType;
18
19 private byte outType;
20
21 public FieldMetadata(string name, TraceLoggingDataType type, EventFieldTags tags, bool variableCount)
22 : this(name, type, tags, (byte)(variableCount ? 64 : 0), 0)
23 {
24 }
25
26 private FieldMetadata(string name, TraceLoggingDataType dataType, EventFieldTags tags, byte countFlags, ushort fixedCount = 0, byte[] custom = null)
27 {
28 if (name == null)
29 {
30 throw new ArgumentNullException("name", "This usually means that the object passed to Write is of a type that does not support being used as the top-level object in an event, e.g. a primitive or built-in type.");
31 }
33 int num = (int)(dataType & (TraceLoggingDataType)31);
34 this.name = name;
35 nameSize = Encoding.UTF8.GetByteCount(this.name) + 1;
36 inType = (byte)(num | countFlags);
37 outType = (byte)((uint)((int)dataType >> 8) & 0x7Fu);
38 this.tags = tags;
39 this.fixedCount = fixedCount;
40 this.custom = custom;
41 if (countFlags != 0)
42 {
43 switch (num)
44 {
45 case 0:
47 case 14:
49 case 1:
50 case 2:
52 }
53 }
54 if ((this.tags & (EventFieldTags)268435455) != 0)
55 {
56 outType |= 128;
57 }
58 if (outType != 0)
59 {
60 inType |= 128;
61 }
62 }
63
65 {
66 inType |= 128;
67 outType++;
68 if ((outType & 0x7F) == 0)
69 {
71 }
72 }
73
74 public void Encode(ref int pos, byte[] metadata)
75 {
76 if (metadata != null)
77 {
78 Encoding.UTF8.GetBytes(name, 0, name.Length, metadata, pos);
79 }
80 pos += nameSize;
81 if (metadata != null)
82 {
83 metadata[pos] = inType;
84 }
85 pos++;
86 if ((inType & 0x80u) != 0)
87 {
88 if (metadata != null)
89 {
90 metadata[pos] = outType;
91 }
92 pos++;
93 if ((outType & 0x80u) != 0)
94 {
95 Statics.EncodeTags((int)tags, ref pos, metadata);
96 }
97 }
98 if ((inType & 0x20) == 0)
99 {
100 return;
101 }
102 if (metadata != null)
103 {
104 metadata[pos] = (byte)fixedCount;
105 metadata[pos + 1] = (byte)(fixedCount >> 8);
106 }
107 pos += 2;
108 if (96 == (inType & 0x60) && fixedCount != 0)
109 {
110 if (metadata != null)
111 {
112 Buffer.BlockCopy(custom, 0, metadata, pos, fixedCount);
113 }
114 pos += fixedCount;
115 }
116 }
117}
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Definition Buffer.cs:102
FieldMetadata(string name, TraceLoggingDataType dataType, EventFieldTags tags, byte countFlags, ushort fixedCount=0, byte[] custom=null)
FieldMetadata(string name, TraceLoggingDataType type, EventFieldTags tags, bool variableCount)
void Encode(ref int pos, byte[] metadata)
static void CheckName(string name)
Definition Statics.cs:66
static void EncodeTags(int tags, ref int pos, byte[] metadata)
Definition Statics.cs:29
static string EventSource_TooManyFields
Definition SR.cs:1282
static string EventSource_NotSupportedArrayOfNil
Definition SR.cs:1260
static string EventSource_NotSupportedArrayOfNullTerminatedString
Definition SR.cs:1262
static string EventSource_NotSupportedArrayOfBinary
Definition SR.cs:1258
Definition SR.cs:7
static Encoding UTF8
Definition Encoding.cs:526