Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start vita49 parsing #8

Merged
merged 13 commits into from
Jul 2, 2024
Prev Previous commit
Next Next commit
more vita49 parsing setup
Anthony Templeton committed Jul 1, 2024
commit b662abfb6a587e6eafa03bd23017d1dbc71bc99a
21 changes: 18 additions & 3 deletions src/vita49.zig
Original file line number Diff line number Diff line change
@@ -31,6 +31,19 @@ pub const Class_ID = packed struct {
oui: u24,
info_class_code: u16,
packet_class_code: u16,

const Self = @This();

pub fn new(stream: [8]u8) Self {
const bytes_1 = stream[0..3];
const bytes_2 = stream[4..];
return .{
.reserved = @as(u8, @truncate((bytes_1 >> 24) & 0xF)),
.oui = @as(u24, @truncate((bytes_1 >> 0xFFFFFF))),
.info_class_code = @as(u16, @truncate((bytes_2 >> 16) & 0xFFFF)),
.packet_class_code = @as(u16, @truncate(bytes_2 & 0xFFFF)),
};
}
};

pub const Trailer = packed struct {
@@ -95,11 +108,13 @@ pub const Vita49 = struct {
const Self = @This();

pub fn new(stream: []const u8) !Self {
const header = try Header.new(stream[0..4]);
const little_endian_stream = std.mem.readInt(u32, &stream, .little);

const header = try Header.new(little_endian_stream[0..4]);
var stream_id: ?32 = undefined;
switch (header.packet_type) {
Packet_Type.ctx_packet, Packet_Type.ext_ctx_packet, Packet_Type.signal_w_stream_id, Packet_Type.ext_data_w_steam_id => {
stream_id = stream[32..63];
Packet_Type.signal_w_stream_id, Packet_Type.ext_data_w_steam_id => {
stream_id = @as(u32, @truncate((little_endian_stream >> 32) & 0xF));
},
Packet_Type.signal_wo_stream_id, Packet_Type.signal_wo_stream_id, Packet_Type.ext_data_wo_steam_id => {},
_ => {