#Why am i getting the wrong platform ids

1 messages · Page 1 of 1 (latest)

median kraken
#
const OffsetTable = packed struct { scaler_type: u32, num_tables: u16, search_range: u16, entry_selector: u16, range_shift: u16 };
const TableDirectory = extern struct {tag: [4]u8,checksum: u32,offset: u32,length: u32,};
fn readOffsetTable(reader: anytype) !OffsetTable {
            var offset_table = try reader.readStruct(OffsetTable);
            std.mem.byteSwapAllFields(OffsetTable, &offset_table);
            return offset_table;
        }
        fn readTableDirectories(self: *Self, reader: anytype) ![]TableDirectory {
            const directories = try self.allocator.alloc(TableDirectory, self.offset_table.num_tables);
            for (directories) |*directory| {
                directory.* = try reader.readStruct(TableDirectory);
                std.mem.byteSwapAllFields(TableDirectory, directory);
                std.debug.print("{s}\n", .{directory.tag});
            }
            return directories;
        }
        
        fn readCmapTable(self: *Self, reader: anytype, buffered_stream: anytype) !void {
            var cmap_table: Cmap = try reader.readStruct(Cmap);
            std.mem.byteSwapAllFields(Cmap, &cmap_table);
            try buffered_stream.seekBy(@bitSizeOf(Cmap) / 8 - @sizeOf(Cmap));
            const encoding_tables: []CmapEncodingTable = try self.allocator.alloc(CmapEncodingTable, cmap_table.no_tables);
            for (encoding_tables, 0..) |*table, i| {
                table.* = try reader.readStruct(CmapEncodingTable);
                std.mem.byteSwapAllFields(CmapEncodingTable, table);
                std.debug.print("{d}: {any}\n", .{ i, table.* });
                try buffered_stream.seekBy(@bitSizeOf(CmapEncodingTable) / 8 - @sizeOf(CmapEncodingTable));
            }
            self.allocator.free(encoding_tables);
        }
#
const CmapEncodingTable = packed struct { platformId: u16, platformSpecificId: u16, offset: u32 };
const CmapSubtable = packed struct { format: u16, length: u16, language: u16 };```
full orchid
#

that's not what packed struct means in zig

#

you want

const Cmap = extern struct { version: u16 align(1), no_tables: u16 align(1) };
const CmapEncodingTable = extern struct { platformId: u16 align(1), platformSpecificId: u16 align(1), offset: u32 align(1) };
const CmapSubtable = extern struct { format: u16 align(1), length: u16 align(1), language: u16 align(1) };
#

not that there are any fields here that need to be packed

median kraken
#

why align 1?

full orchid
#

that's what the packed attributes in C does, it changes the alignment of every field to 1

median kraken
#

ok let me try

full orchid
#

and you need extern struct which means "C compatible struct"

median kraken
#

but iam seeking by with @bitSizeof(struct)/8 - sizeOf(struct) right

full orchid
#

I mean that's just 0 now

median kraken
#

@full orchid iam still getting the same output