tiny.quic.connection.stream.ring
Defined in connection.stream.
API (2)
Actions
Public operations.
read: Fills the output from the buffer fromindexon, carrying on at the buffer start where it runs off the end.write: Copies the input into the buffer fromindexon, carrying on at the buffer start where it runs off the end.
Source
Source: lib/quic/src/connection/stream/ring.zig
zig
const std = @import("std");/// Copies the input into the buffer from `index` on, carrying on at the buffer start where it runs/// off the end. The index sits inside the buffer and the input fits. The sending and receiving/// parts both buffer stream bytes through this write.pub fn write(ring: []u8, index: usize, input: []const u8) void { std.debug.assert(index < ring.len); std.debug.assert(input.len <= ring.len); const first = @min(input.len, ring.len - index); @memcpy(ring[index..][0..first], input[0..first]); @memcpy(ring[0 .. input.len - first], input[first..]);}/// Fills the output from the buffer from `index` on, carrying on at the buffer start where it runs/// off the end. The index sits inside the buffer and the output fits. The receiving part hands an/// application its bytes through this read.pub fn read(ring: []const u8, index: usize, output: []u8) void { std.debug.assert(index < ring.len); std.debug.assert(output.len <= ring.len); const first = @min(output.len, ring.len - index); @memcpy(output[0..first], ring[index..][0..first]); @memcpy(output[first..], ring[0 .. output.len - first]);}test "ring copies wrap once at the buffer end" { var ring: [4]u8 = @splat(0); write(&ring, 3, "abc"); try std.testing.expectEqualSlices(u8, &.{ 'b', 'c', 0, 'a' }, &ring); var output: [3]u8 = undefined; read(&ring, 3, &output); try std.testing.expectEqualStrings("abc", &output); write(&ring, 0, "wxyz"); try std.testing.expectEqualStrings("wxyz", &ring);}Source: lib/quic/src/connection/stream/root.zig:7
zig
pub const ring = @import("ring.zig");Audit
| Definitions | 3 |
|---|---|
| Public names | 3 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |