Skip to content

Commit 56e9d99

Browse files
🐛 ♻️
1 parent 6371685 commit 56e9d99

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

TronDotNet/Lite3.Core.C.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private static Status VerifyKey(
143143
[MethodImpl(MethodImplOptions.AggressiveInlining)]
144144
private static Status VerifyValue(ReadOnlySpan<byte> buffer, ref int offset)
145145
{
146-
if (ValueSize > buffer.Length || offset > buffer.Length - ValueSize)
146+
if (ValueHeaderSize > buffer.Length || offset > buffer.Length - ValueHeaderSize)
147147
{
148148
_logger.LogError("VALUE OUT OF BOUNDS");
149149
return Status.ValueOutOfBounds;
@@ -156,7 +156,7 @@ private static Status VerifyValue(ReadOnlySpan<byte> buffer, ref int offset)
156156
return Status.ValueKindInvalid;
157157
}
158158

159-
var valueEntrySize = ValueSize + ValueKindSizes[(int)kind];
159+
var valueEntrySize = ValueHeaderSize + ValueKindSizes[(int)kind];
160160
if (valueEntrySize > buffer.Length || offset > buffer.Length - valueEntrySize)
161161
{
162162
_logger.LogError("VALUE OUT OF BOUNDS");
@@ -167,7 +167,7 @@ private static Status VerifyValue(ReadOnlySpan<byte> buffer, ref int offset)
167167
{
168168
var byteCount = 0;
169169
for (var i = 0; i < ValueKindSizes[(int)ValueKind.Bytes]; i++)
170-
byteCount |= buffer[offset + ValueSize + i] << (8 * i);
170+
byteCount |= buffer[offset + ValueHeaderSize + i] << (8 * i);
171171

172172
valueEntrySize += byteCount;
173173

@@ -614,7 +614,7 @@ public static Status InitializeArray(Span<byte> buffer, out int position)
614614
/// <para>
615615
/// <b>Note</b>: this function expects the caller to write to:
616616
/// <list type="number">
617-
/// <item><see cref="ValueEntry.Type" />: the value type (length of <see cref="ValueSize" />).</item>
617+
/// <item><see cref="ValueEntry.Type" />: the value type (length of <see cref="ValueHeaderSize" />).</item>
618618
/// <item><see cref="ValueEntry.Value" />: the actual value (length of <see cref="valueLength" />).</item>
619619
/// </list>
620620
/// </para>
@@ -656,7 +656,7 @@ private static Status SetImpl(
656656
((keyData.Size >> (16 - KeyTagKeySizeShift) != 0 ? 1 : 0) << 1) +
657657
(keyData.Size >> (8 - KeyTagKeySizeShift) != 0 ? 1 : 0) +
658658
(keyData.Size != 0 ? 1 : 0);
659-
var baseEntrySize = keyTagSize + (int)keyData.Size + ValueSize + valueLength;
659+
var baseEntrySize = keyTagSize + (int)keyData.Size + ValueHeaderSize + valueLength;
660660

661661
if ((offset & NodeAlignmentMask) != 0)
662662
{
@@ -958,7 +958,7 @@ private static Status SetImpl(
958958

959959
valueStartOffset = position;
960960
value = new ValueEntry(buffer, position);
961-
position += ValueSize + valueLength;
961+
position += ValueHeaderSize + valueLength;
962962

963963
_logger.LogProbe("OK");
964964
return 0;

TronDotNet/Lite3.Core.H.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public readonly ref struct ReadOnlyValueEntry(ReadOnlySpan<byte> buffer, int sta
103103
private readonly ReadOnlySpan<byte> _buffer = buffer;
104104
internal ValueKind Type => (ValueKind)_buffer[Offset];
105105
public readonly int Offset = startOffset;
106-
internal readonly int ValueOffset = startOffset + ValueSize;
106+
internal readonly int ValueOffset = startOffset + ValueHeaderSize;
107107
internal ReadOnlySpan<byte> Value => _buffer[ValueOffset..];
108108
}
109109

@@ -112,10 +112,10 @@ internal ref struct ValueEntry(Span<byte> buffer, int startOffset)
112112
{
113113
private Span<byte> _buffer = buffer;
114114
public ref byte Type => ref _buffer[startOffset];
115-
public Span<byte> Value => _buffer[(startOffset + ValueSize)..];
115+
public Span<byte> Value => _buffer[(startOffset + ValueHeaderSize)..];
116116
}
117117

118-
private const int ValueSize = 1;
118+
internal const int ValueHeaderSize = 1;
119119

120120
/// <remarks><em>Ported from C <c>lite3_type_sizes</c>.</em></remarks>
121121
internal static readonly int[] ValueKindSizes =
@@ -126,8 +126,8 @@ internal ref struct ValueEntry(Span<byte> buffer, int startOffset)
126126
8, // F64
127127
4, // Bytes
128128
4, // String
129-
NodeSize - ValueSize, // Object
130-
NodeSize - ValueSize, // Array
129+
NodeSize - ValueHeaderSize, // Object
130+
NodeSize - ValueHeaderSize, // Array
131131
0 // Invalid
132132
];
133133

TronDotNet/Tron.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ public string GetStringValue(TronContext context)
108108
[MethodImpl(MethodImplOptions.AggressiveInlining)]
109109
public int GetSize()
110110
{
111-
var result = Lite3.GetValueSize(value);
112-
if (value.Type is Lite3.ValueKind.String or Lite3.ValueKind.Bytes)
113-
result += Lite3.ValueKindSizes[(int)value.Type];
114-
return result;
111+
return Lite3.ValueHeaderSize + Lite3.GetValueSize(value);
115112
}
116113

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

0 commit comments

Comments
 (0)