Skip to content

Commit 99e91fe

Browse files
🎨
1 parent 6555c96 commit 99e91fe

File tree

2 files changed

+161
-157
lines changed

2 files changed

+161
-157
lines changed

Lite3DotNet/EntryExtensions.cs

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
using System.Runtime.CompilerServices;
2+
using System.Text;
3+
4+
namespace Lite3DotNet;
5+
6+
public static class EntryExtensions
7+
{
8+
extension(Lite3Core.StringEntry value)
9+
{
10+
/// <inheritdoc cref="Lite3Core.GetUtf8Value" />
11+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
12+
public bool TryGetUtf8Value(ReadOnlySpan<byte> buffer, out ReadOnlySpan<byte> result)
13+
{
14+
return Lite3Core.GetUtf8Value(buffer, value, out result) < 0;
15+
}
16+
17+
/// <inheritdoc cref="Lite3Core.GetUtf8Value" />
18+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
19+
public ReadOnlySpan<byte> GetUtf8Value(ReadOnlySpan<byte> buffer)
20+
{
21+
Lite3Core.Status status;
22+
return (status = Lite3Core.GetUtf8Value(buffer, value, out var result)) >= 0
23+
? result
24+
: throw status.AsException();
25+
}
26+
27+
/// <inheritdoc cref="Lite3Core.GetUtf8Value" />
28+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
29+
public bool TryGetUtf8Value(Lite3Context context, out ReadOnlySpan<byte> result)
30+
{
31+
return Lite3Core.GetUtf8Value(context.Buffer, value, out result) >= 0;
32+
}
33+
34+
/// <inheritdoc cref="Lite3Core.GetUtf8Value" />
35+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
36+
public ReadOnlySpan<byte> GetUtf8Value(Lite3Context context)
37+
{
38+
Lite3Core.Status status;
39+
return (status = Lite3Core.GetUtf8Value(context.Buffer, value, out var result)) >= 0
40+
? result
41+
: throw status.AsException();
42+
}
43+
44+
/// <summary>
45+
/// <para><b><em>Do not use for performance-sensitive code</em></b>.</para>
46+
/// <para>Convenience method for getting a converted .NET-native UTF-16 string.</para>
47+
/// </summary>
48+
/// <seealso cref="Lite3Core.GetUtf8Value"/>
49+
/// <param name="buffer">The message buffer.</param>
50+
/// <returns>The converted UTF-16 string value.</returns>
51+
public string GetStringValue(ReadOnlySpan<byte> buffer)
52+
{
53+
Lite3Core.Status status;
54+
return (status = Lite3Core.GetUtf8Value(buffer, value, out var result)) >= 0
55+
? Encoding.UTF8.GetString(result)
56+
: throw status.AsException();
57+
}
58+
59+
/// <summary>
60+
/// <para><b><em>Do not use for performance-sensitive code</em></b>.</para>
61+
/// <para>Convenience method for getting a converted .NET-native UTF-16 string.</para>
62+
/// </summary>
63+
/// <seealso cref="Lite3Core.GetUtf8Value"/>
64+
/// <param name="context">The context.</param>
65+
/// <returns>The converted UTF-16 string value.</returns>
66+
public string GetStringValue(Lite3Context context)
67+
{
68+
Lite3Core.Status status;
69+
return (status = Lite3Core.GetUtf8Value(context.Buffer, value, out var result)) >= 0
70+
? Encoding.UTF8.GetString(result)
71+
: throw status.AsException();
72+
}
73+
}
74+
75+
extension(Lite3Core.ValueEntry value)
76+
{
77+
/// <inheritdoc cref="Lite3Core.GetValueKind(in Lite3Core.ValueEntry)" />
78+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
79+
public Lite3Core.ValueKind GetValueKind() => Lite3Core.GetValueKind(value);
80+
81+
/// <inheritdoc cref="Lite3Core.GetValueSize" />
82+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
83+
public int GetValueSize() => Lite3Core.GetValueSize(value);
84+
85+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
86+
public int GetSize()
87+
{
88+
return Lite3Core.ValueHeaderSize +
89+
value.Type switch
90+
{
91+
Lite3Core.ValueKind.String => Lite3Core.StringLengthSize,
92+
Lite3Core.ValueKind.Bytes => Lite3Core.BytesLengthSize,
93+
_ => 0
94+
} +
95+
Lite3Core.GetValueSize(value);
96+
}
97+
98+
/// <inheritdoc cref="Lite3Core.ValueIsNull" />
99+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
100+
public bool IsNull() => Lite3Core.ValueIsNull(value);
101+
102+
/// <inheritdoc cref="Lite3Core.ValueIsBool" />
103+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
104+
public bool IsBool() => Lite3Core.ValueIsBool(value);
105+
106+
/// <inheritdoc cref="Lite3Core.ValueIsLong" />
107+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
108+
public bool IsLong() => Lite3Core.ValueIsLong(value);
109+
110+
/// <inheritdoc cref="Lite3Core.ValueIsDouble" />
111+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
112+
public bool IsDouble() => Lite3Core.ValueIsDouble(value);
113+
114+
/// <inheritdoc cref="Lite3Core.ValueIsBytes" />
115+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
116+
public bool IsBytes() => Lite3Core.ValueIsBytes(value);
117+
118+
/// <inheritdoc cref="Lite3Core.ValueIsString" />
119+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
120+
public bool IsString() => Lite3Core.ValueIsString(value);
121+
122+
/// <inheritdoc cref="Lite3Core.ValueIsObject" />
123+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
124+
public bool IsObject() => Lite3Core.ValueIsObject(value);
125+
126+
/// <inheritdoc cref="Lite3Core.ValueIsArray" />
127+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
128+
public bool IsArray() => Lite3Core.ValueIsArray(value);
129+
130+
/// <inheritdoc cref="Lite3Core.GetValueBool" />
131+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
132+
public bool GetBool() => Lite3Core.GetValueBool(value);
133+
134+
/// <inheritdoc cref="Lite3Core.GetValueLong" />
135+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
136+
public long GetLong() => Lite3Core.GetValueLong(value);
137+
138+
/// <inheritdoc cref="Lite3Core.GetValueDouble" />
139+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
140+
public double GetDouble() => Lite3Core.GetValueDouble(value);
141+
142+
/// <inheritdoc cref="Lite3Core.GetUtf8Value" />
143+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
144+
public ReadOnlySpan<byte> GetUtf8() => Lite3Core.GetValueUtf8(value);
145+
146+
/// <summary>
147+
/// <para><b><em>Do not use for performance-sensitive code</em></b>.</para>
148+
/// <para>Convenience method for getting a converted .NET-native UTF-16 string.</para>
149+
/// </summary>
150+
/// <seealso cref="Lite3Core.GetUtf8Value"/>
151+
/// <returns>The converted UTF-16 string value.</returns>
152+
public string GetStringValue()
153+
{
154+
return Encoding.UTF8.GetString(Lite3Core.GetValueUtf8(value));
155+
}
156+
157+
/// <inheritdoc cref="Lite3Core.GetValueBytes" />
158+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
159+
public ReadOnlySpan<byte> GetBytes() => Lite3Core.GetValueBytes(value);
160+
}
161+
}

Lite3DotNet/Lite3.cs

Lines changed: 0 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using System.Runtime.CompilerServices;
2-
using System.Text;
3-
41
namespace Lite3DotNet;
52

63
public static partial class Lite3
@@ -27,158 +24,4 @@ public static Lite3Enumerable Enumerate(ReadOnlySpan<byte> buffer, int offset, b
2724
{
2825
return new Lite3Enumerable(buffer, offset, withKey, withOffset);
2926
}
30-
31-
extension(Lite3Core.StringEntry value)
32-
{
33-
/// <inheritdoc cref="Lite3Core.GetUtf8Value" />
34-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
35-
public bool TryGetUtf8Value(ReadOnlySpan<byte> buffer, out ReadOnlySpan<byte> result)
36-
{
37-
return Lite3Core.GetUtf8Value(buffer, value, out result) < 0;
38-
}
39-
40-
/// <inheritdoc cref="Lite3Core.GetUtf8Value" />
41-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
42-
public ReadOnlySpan<byte> GetUtf8Value(ReadOnlySpan<byte> buffer)
43-
{
44-
Lite3Core.Status status;
45-
return (status = Lite3Core.GetUtf8Value(buffer, value, out var result)) >= 0
46-
? result
47-
: throw status.AsException();
48-
}
49-
50-
/// <inheritdoc cref="Lite3Core.GetUtf8Value" />
51-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
52-
public bool TryGetUtf8Value(Lite3Context context, out ReadOnlySpan<byte> result)
53-
{
54-
return Lite3Core.GetUtf8Value(context.Buffer, value, out result) >= 0;
55-
}
56-
57-
/// <inheritdoc cref="Lite3Core.GetUtf8Value" />
58-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
59-
public ReadOnlySpan<byte> GetUtf8Value(Lite3Context context)
60-
{
61-
Lite3Core.Status status;
62-
return (status = Lite3Core.GetUtf8Value(context.Buffer, value, out var result)) >= 0
63-
? result
64-
: throw status.AsException();
65-
}
66-
67-
/// <summary>
68-
/// <para><b><em>Do not use for performance-sensitive code</em></b>.</para>
69-
/// <para>Convenience method for getting a converted .NET-native UTF-16 string.</para>
70-
/// </summary>
71-
/// <seealso cref="Lite3Core.GetUtf8Value"/>
72-
/// <param name="buffer">The message buffer.</param>
73-
/// <returns>The converted UTF-16 string value.</returns>
74-
public string GetStringValue(ReadOnlySpan<byte> buffer)
75-
{
76-
Lite3Core.Status status;
77-
return (status = Lite3Core.GetUtf8Value(buffer, value, out var result)) >= 0
78-
? Encoding.UTF8.GetString(result)
79-
: throw status.AsException();
80-
}
81-
82-
/// <summary>
83-
/// <para><b><em>Do not use for performance-sensitive code</em></b>.</para>
84-
/// <para>Convenience method for getting a converted .NET-native UTF-16 string.</para>
85-
/// </summary>
86-
/// <seealso cref="Lite3Core.GetUtf8Value"/>
87-
/// <param name="context">The context.</param>
88-
/// <returns>The converted UTF-16 string value.</returns>
89-
public string GetStringValue(Lite3Context context)
90-
{
91-
Lite3Core.Status status;
92-
return (status = Lite3Core.GetUtf8Value(context.Buffer, value, out var result)) >= 0
93-
? Encoding.UTF8.GetString(result)
94-
: throw status.AsException();
95-
}
96-
}
97-
98-
extension(Lite3Core.ValueEntry value)
99-
{
100-
/// <inheritdoc cref="Lite3Core.GetValueKind(in Lite3Core.ValueEntry)" />
101-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
102-
public Lite3Core.ValueKind GetValueKind() => Lite3Core.GetValueKind(value);
103-
104-
/// <inheritdoc cref="Lite3Core.GetValueSize" />
105-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
106-
public int GetValueSize() => Lite3Core.GetValueSize(value);
107-
108-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
109-
public int GetSize()
110-
{
111-
return Lite3Core.ValueHeaderSize +
112-
value.Type switch
113-
{
114-
Lite3Core.ValueKind.String => Lite3Core.StringLengthSize,
115-
Lite3Core.ValueKind.Bytes => Lite3Core.BytesLengthSize,
116-
_ => 0
117-
} +
118-
Lite3Core.GetValueSize(value);
119-
}
120-
121-
/// <inheritdoc cref="Lite3Core.ValueIsNull" />
122-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
123-
public bool IsNull() => Lite3Core.ValueIsNull(value);
124-
125-
/// <inheritdoc cref="Lite3Core.ValueIsBool" />
126-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
127-
public bool IsBool() => Lite3Core.ValueIsBool(value);
128-
129-
/// <inheritdoc cref="Lite3Core.ValueIsLong" />
130-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
131-
public bool IsLong() => Lite3Core.ValueIsLong(value);
132-
133-
/// <inheritdoc cref="Lite3Core.ValueIsDouble" />
134-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
135-
public bool IsDouble() => Lite3Core.ValueIsDouble(value);
136-
137-
/// <inheritdoc cref="Lite3Core.ValueIsBytes" />
138-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
139-
public bool IsBytes() => Lite3Core.ValueIsBytes(value);
140-
141-
/// <inheritdoc cref="Lite3Core.ValueIsString" />
142-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
143-
public bool IsString() => Lite3Core.ValueIsString(value);
144-
145-
/// <inheritdoc cref="Lite3Core.ValueIsObject" />
146-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
147-
public bool IsObject() => Lite3Core.ValueIsObject(value);
148-
149-
/// <inheritdoc cref="Lite3Core.ValueIsArray" />
150-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
151-
public bool IsArray() => Lite3Core.ValueIsArray(value);
152-
153-
/// <inheritdoc cref="Lite3Core.GetValueBool" />
154-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
155-
public bool GetBool() => Lite3Core.GetValueBool(value);
156-
157-
/// <inheritdoc cref="Lite3Core.GetValueLong" />
158-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
159-
public long GetLong() => Lite3Core.GetValueLong(value);
160-
161-
/// <inheritdoc cref="Lite3Core.GetValueDouble" />
162-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
163-
public double GetDouble() => Lite3Core.GetValueDouble(value);
164-
165-
/// <inheritdoc cref="Lite3Core.GetUtf8Value" />
166-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
167-
public ReadOnlySpan<byte> GetUtf8() => Lite3Core.GetValueUtf8(value);
168-
169-
/// <summary>
170-
/// <para><b><em>Do not use for performance-sensitive code</em></b>.</para>
171-
/// <para>Convenience method for getting a converted .NET-native UTF-16 string.</para>
172-
/// </summary>
173-
/// <seealso cref="Lite3Core.GetUtf8Value"/>
174-
/// <returns>The converted UTF-16 string value.</returns>
175-
public string GetStringValue()
176-
{
177-
return Encoding.UTF8.GetString(Lite3Core.GetValueUtf8(value));
178-
}
179-
180-
/// <inheritdoc cref="Lite3Core.GetValueBytes" />
181-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
182-
public ReadOnlySpan<byte> GetBytes() => Lite3Core.GetValueBytes(value);
183-
}
18427
}

0 commit comments

Comments
 (0)