forked from NethermindEth/nethermind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSsz.Encode.cs
More file actions
35 lines (31 loc) · 893 Bytes
/
Ssz.Encode.cs
File metadata and controls
35 lines (31 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only
using System;
using System.Collections;
namespace Nethermind.Serialization.Ssz;
public static partial class Ssz
{
public static void Encode(Span<byte> span, BitArray? vector)
{
if (vector is null)
{
return;
}
int byteLength = (vector.Length + 7) / 8;
byte[] bytes = new byte[byteLength];
vector.CopyTo(bytes, 0);
Encode(span, bytes);
}
public static void Encode(Span<byte> span, BitArray? list, int limit)
{
if (list is null)
{
return;
}
int byteLength = (list.Length + 8) / 8;
byte[] bytes = new byte[byteLength];
list.CopyTo(bytes, 0);
bytes[byteLength - 1] |= (byte)(1 << (list.Length % 8));
Encode(span, bytes);
}
}