Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

encodeToSlice

Public Function
std.crypto.codecs.asn1.Tag.encodeToSlice
pub fn encodeToSlice(self: Tag, buf: *[max_encoded_len]u8) []const u8

Params

File

crypto/codecs/asn1.zig:95
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    pub fn encodeToSlice(self: Tag, buf: *[max_encoded_len]u8) []const u8 {
        const n = @backingInt(self.number);
        var tag1: FirstTag = .{
            .number = undefined,
            .constructed = self.constructed,
            .class = self.class,
        };

        if (n < high_tag_marker) {
            tag1.number = @intCast(n);
            buf[0] = @bitCast(tag1);
            return buf[0..1];
        }

        tag1.number = high_tag_marker;
        buf[0] = @bitCast(tag1);

        const bits_used = @bitSizeOf(@TypeOf(n)) - @clz(n);
        const len = std.math.divCeil(usize, bits_used, 7) catch unreachable;

        var remaining = n;
        var i = len;
        while (i > 0) : (i -= 1) {
            buf[i] = @bitCast(NextTag{
                .number = @truncate(remaining),
                .continues = i != len,
            });
            remaining >>= 7;
        }
        return buf[0 .. 1 + len];
    }