a
This commit is contained in:
parent
14ee65417e
commit
aded7d0a82
|
@ -52,7 +52,6 @@ pub const Client = struct {
|
||||||
|
|
||||||
try write.add_message(list.writer(), s.allocator, map);
|
try write.add_message(list.writer(), s.allocator, map);
|
||||||
try dumpDebug("ClientInit.bin", list);
|
try dumpDebug("ClientInit.bin", list);
|
||||||
|
|
||||||
try s.stream.writer().writeAll(list.items);
|
try s.stream.writer().writeAll(list.items);
|
||||||
}
|
}
|
||||||
pub fn quassel_login(s: *Client, username: []const u8, password: []const u8) !void {
|
pub fn quassel_login(s: *Client, username: []const u8, password: []const u8) !void {
|
||||||
|
|
|
@ -28,11 +28,25 @@ pub fn get_bytearray(reader: anytype, allocator: *std.mem.Allocator) !std.ArrayL
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_string(reader: anytype, allocator: *std.mem.Allocator) ![]u8 {
|
pub fn get_string(reader: anytype, allocator: *std.mem.Allocator) ![]u8 {
|
||||||
return try reader.readUntilDelimiterAlloc(
|
var data = std.ArrayList(u8).init(allocator);
|
||||||
allocator,
|
defer data.deinit();
|
||||||
'\x00',
|
var length = try reader.readIntBig(i32);
|
||||||
1024,
|
|
||||||
);
|
var index: usize = 0;
|
||||||
|
while (true) {
|
||||||
|
if (index == length) break;
|
||||||
|
|
||||||
|
const byte = try reader.readIntBig(u16);
|
||||||
|
try data.append(@intCast(u8, byte));
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ut8Str = try allocator.alloc(u8, @intCast(usize, length));
|
||||||
|
for (data.items) |char, i| {
|
||||||
|
ut8Str[i] = char;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ut8Str;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_stringlist(reader: anytype, allocator: *std.mem.Allocator) !std.ArrayList([]const u8) {
|
pub fn get_stringlist(reader: anytype, allocator: *std.mem.Allocator) !std.ArrayList([]const u8) {
|
||||||
|
@ -85,5 +99,6 @@ pub fn get_variant_t(reader: anytype, type_id: u32, allocator: *std.mem.Allocato
|
||||||
|
|
||||||
pub fn get_variant(reader: anytype, allocator: *std.mem.Allocator) !qvar.QVariant {
|
pub fn get_variant(reader: anytype, allocator: *std.mem.Allocator) !qvar.QVariant {
|
||||||
var type_id = try get_qvariant(reader);
|
var type_id = try get_qvariant(reader);
|
||||||
|
_ = try get_byte(reader);
|
||||||
return try get_variant_t(reader, type_id, allocator);
|
return try get_variant_t(reader, type_id, allocator);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ test "read/write string" {
|
||||||
|
|
||||||
var arr = "Hello World!".*;
|
var arr = "Hello World!".*;
|
||||||
|
|
||||||
try write.add_string(byteList.writer(), &arr);
|
try write.add_string(byteList.writer(), global_allocator, &arr);
|
||||||
|
|
||||||
var fBS = std.io.fixedBufferStream(byteList.items);
|
var fBS = std.io.fixedBufferStream(byteList.items);
|
||||||
var val = try read.get_string(fBS.reader(), global_allocator);
|
var val = try read.get_string(fBS.reader(), global_allocator);
|
||||||
|
@ -87,7 +87,7 @@ test "read/write stringlist" {
|
||||||
try arr.append("Hewwo");
|
try arr.append("Hewwo");
|
||||||
try arr.append("World");
|
try arr.append("World");
|
||||||
|
|
||||||
try write.add_stringlist(byteList.writer(), arr);
|
try write.add_stringlist(byteList.writer(), global_allocator, arr);
|
||||||
|
|
||||||
var fBS = std.io.fixedBufferStream(byteList.items);
|
var fBS = std.io.fixedBufferStream(byteList.items);
|
||||||
var val = try read.get_stringlist(fBS.reader(), global_allocator);
|
var val = try read.get_stringlist(fBS.reader(), global_allocator);
|
||||||
|
|
|
@ -19,6 +19,7 @@ pub fn add_bytearray(writer: anytype, array: std.ArrayList(u8)) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_string(writer: anytype, allocator: *std.mem.Allocator, str: []const u8) !void {
|
pub fn add_string(writer: anytype, allocator: *std.mem.Allocator, str: []const u8) !void {
|
||||||
|
try writer.writeIntBig(i32, @intCast(i32, str.len));
|
||||||
var ut16Str = try allocator.alloc(u16, str.len);
|
var ut16Str = try allocator.alloc(u16, str.len);
|
||||||
defer allocator.free(ut16Str);
|
defer allocator.free(ut16Str);
|
||||||
for (str) |character, index| {
|
for (str) |character, index| {
|
||||||
|
@ -26,8 +27,6 @@ pub fn add_string(writer: anytype, allocator: *std.mem.Allocator, str: []const u
|
||||||
}
|
}
|
||||||
|
|
||||||
try writer.writeAll(std.mem.sliceAsBytes(ut16Str));
|
try writer.writeAll(std.mem.sliceAsBytes(ut16Str));
|
||||||
try writer.writeByte('\x00');
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_stringlist(writer: anytype, allocator: *std.mem.Allocator, strList: std.ArrayList([]const u8)) !void {
|
pub fn add_stringlist(writer: anytype, allocator: *std.mem.Allocator, strList: std.ArrayList([]const u8)) !void {
|
||||||
|
@ -40,6 +39,7 @@ pub fn add_stringlist(writer: anytype, allocator: *std.mem.Allocator, strList: s
|
||||||
// Call this and Then write your type
|
// Call this and Then write your type
|
||||||
pub fn add_qvariant_with_id(writer: anytype, type_id: u32) !void {
|
pub fn add_qvariant_with_id(writer: anytype, type_id: u32) !void {
|
||||||
try add_int(writer, type_id);
|
try add_int(writer, type_id);
|
||||||
|
try add_byte(writer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_qvariant(writer: anytype, allocator: *std.mem.Allocator, variant: qvar.QVariant) !void {
|
pub fn add_qvariant(writer: anytype, allocator: *std.mem.Allocator, variant: qvar.QVariant) !void {
|
||||||
|
@ -82,7 +82,7 @@ pub fn add_qvariantmap(writer: anytype, allocator: *std.mem.Allocator, map: std.
|
||||||
|
|
||||||
// qvariantmap type
|
// qvariantmap type
|
||||||
try add_int(writer, 8); // 4
|
try add_int(writer, 8); // 4
|
||||||
// validity?
|
// unknown value
|
||||||
try add_byte(writer, 0); // 1
|
try add_byte(writer, 0); // 1
|
||||||
// elements
|
// elements
|
||||||
try add_int(writer, map.count()); // 4
|
try add_int(writer, map.count()); // 4
|
||||||
|
|
Loading…
Reference in a new issue