Skip to content

Commit

Permalink
feat: added remained and assert
Browse files Browse the repository at this point in the history
  • Loading branch information
speed2exe committed Nov 4, 2023
1 parent 83fe36a commit 4126320
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/protocol/column_definition.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ pub const ColumnDefinition41 = struct {
column_definition_41.flags = reader.readUInt16();
column_definition_41.decimals = reader.readByte();

// https://mariadb.com/kb/en/result-set-packets/#column-definition-packet
// According to mariadb, there seem to be extra 2 bytes at the end that is not being used
std.debug.assert(reader.remained() == 2);

return column_definition_41;
}
};
4 changes: 4 additions & 0 deletions src/protocol/packet_reader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,8 @@ pub const PacketReader = struct {
pub fn finished(packet_reader: *PacketReader) bool {
return packet_reader.pos == packet_reader.payload.len;
}

pub fn remained(packet_reader: *PacketReader) usize {
return packet_reader.payload.len - packet_reader.pos;
}
};

0 comments on commit 4126320

Please sign in to comment.