1- using System . Runtime . CompilerServices ;
2- using System . Text ;
3-
41namespace Lite3DotNet ;
52
63public 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