Skip to content

Commit 449bdd0

Browse files
🐛 ♻️
1 parent 56e9d99 commit 449bdd0

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

TronDotNet/Lite3.Core.H.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ public enum ValueKind : byte
9898
/// <para>To discover types inside a message, compare against <see cref="ValueEntry.Type" /></para>
9999
/// </summary>
100100
/// <remarks><em>Ported from C <c>lite3_val</c>.</em></remarks>
101-
public readonly ref struct ReadOnlyValueEntry(ReadOnlySpan<byte> buffer, int startOffset)
101+
public readonly ref struct ReadOnlyValueEntry(ReadOnlySpan<byte> buffer, int offset)
102102
{
103103
private readonly ReadOnlySpan<byte> _buffer = buffer;
104104
internal ValueKind Type => (ValueKind)_buffer[Offset];
105-
public readonly int Offset = startOffset;
106-
internal readonly int ValueOffset = startOffset + ValueHeaderSize;
105+
public readonly int Offset = offset;
106+
internal readonly int ValueOffset = offset + ValueHeaderSize;
107107
internal ReadOnlySpan<byte> Value => _buffer[ValueOffset..];
108108
}
109109

@@ -157,7 +157,7 @@ public ref struct BytesEntry(uint gen, int length, int offset)
157157
public readonly int Offset = offset;
158158
}
159159

160-
private const int BytesLengthSize = sizeof(int);
160+
internal const int BytesLengthSize = sizeof(int);
161161

162162
/// <summary>
163163
/// <para>Holds a reference to a string value inside a message buffer.</para>
@@ -180,7 +180,7 @@ public struct StringEntry(uint gen, int length, int offset)
180180
public int Offset = offset;
181181
}
182182

183-
private const int StringLengthSize = sizeof(int);
183+
internal const int StringLengthSize = sizeof(int);
184184

185185
/// <summary>
186186
/// <para>Generational safe access wrapper.</para>

TronDotNet/Tron.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,18 @@ public string GetStringValue(TronContext context)
104104
/// <inheritdoc cref="Lite3.GetValueSize" />
105105
[MethodImpl(MethodImplOptions.AggressiveInlining)]
106106
public int GetValueSize() => Lite3.GetValueSize(value);
107-
107+
108108
[MethodImpl(MethodImplOptions.AggressiveInlining)]
109109
public int GetSize()
110110
{
111-
return Lite3.ValueHeaderSize + Lite3.GetValueSize(value);
111+
return Lite3.ValueHeaderSize +
112+
value.Type switch
113+
{
114+
Lite3.ValueKind.String => Lite3.StringLengthSize,
115+
Lite3.ValueKind.Bytes => Lite3.BytesLengthSize,
116+
_ => 0
117+
} +
118+
Lite3.GetValueSize(value);
112119
}
113120

114121
/// <inheritdoc cref="Lite3.ValueIsNull" />

0 commit comments

Comments
 (0)