array
Function parameters
Parameters
- Len:type
- Elem:type
- elems:anytype
Type definitions in this namespace
Types
- ApplicationCipher
- Encryption parameters for application traffic.
- Decoder
- An abstraction to ensure that protocol-parsing code does not perform an
Functions in this namespace
Functions
= 5
Values
- max_ciphertext_inner_record_len
- = 1 << 14
- max_ciphertext_len
- = max_ciphertext_inner_record_len + 256
- max_ciphertext_record_len
- = max_ciphertext_len + record_header_len
- hello_retry_request_sequence
- = [32]u8{ 0xCF, 0x21, 0xAD, 0x74, 0xE5, 0x9A, 0x61, 0x11, 0xBE, 0x1D, 0x8C, 0x02, 0x1E, 0x65, 0xB8, 0x91, 0xC2, 0xA2, 0x11, 0x16, 0x7A, 0xBB, 0x8C, 0x5E, 0x07, 0x9E, 0x09, 0xE2, 0xC8, 0xA8, 0x33, 0x9C, }
- close_notify_alert
- = [_]u8{ @intFromEnum(Alert.Level.warning), @intFromEnum(Alert.Description.close_notify), }
Source
Implementation
pub fn array(
comptime Len: type,
comptime Elem: type,
elems: anytype,
) [@divExact(@bitSizeOf(Len), 8) + @divExact(@bitSizeOf(Elem), 8) * elems.len]u8 {
const len_size = @divExact(@bitSizeOf(Len), 8);
const elem_size = @divExact(@bitSizeOf(Elem), 8);
var arr: [len_size + elem_size * elems.len]u8 = undefined;
std.mem.writeInt(Len, arr[0..len_size], @intCast(elem_size * elems.len), .big);
const ElemInt = @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(Elem) } });
for (0.., @as([elems.len]Elem, elems)) |index, elem| {
std.mem.writeInt(
ElemInt,
arr[len_size + elem_size * index ..][0..elem_size],
switch (@typeInfo(Elem)) {
.int => @as(Elem, elem),
.@"enum" => @intFromEnum(@as(Elem, elem)),
else => @bitCast(@as(Elem, elem)),
},
.big,
);
}
return arr;
}