@@ 103,3 103,46 @@ test "unmarshal struct" {
try expectEqual(@as(usize, 2), coords.y);
try expectEqual(@as(usize, 3), coords.z);
}
+
+test "unmarshal omitted fields" {
+ const Coordinates = struct {
+ x: usize,
+ y: usize,
+ // TODO: we don't have omitted fields, just optional.
+ //z: ?usize,
+ };
+ const payload = &[_]u8{ 0x01, 0x02 };
+ var fbs = io.fixedBufferStream(payload);
+ const reader = fbs.reader();
+ var d = decoder(testing.allocator, reader);
+ defer d.deinit();
+ const coords = try d.decode(Coordinates);
+ try expectEqual(@as(usize, 1), coords.x);
+ try expectEqual(@as(usize, 2), coords.y);
+}
+
+test "unmarshal array" {
+ const payload = &[_]u8{ 0x11, 0x22, 0x33, 0x44 };
+ var fbs = io.fixedBufferStream(payload);
+ const reader = fbs.reader();
+ var d = decoder(testing.allocator, reader);
+ defer d.deinit();
+ const val = try d.decode([4]u8);
+ try expectEqual(@as(usize, 0x11), val[0]);
+ try expectEqual(@as(usize, 0x22), val[1]);
+ try expectEqual(@as(usize, 0x33), val[2]);
+ try expectEqual(@as(usize, 0x44), val[3]);
+}
+
+test "unmarshal slice" {
+ const payload = &[_]u8{ 0x04, 0x11, 0x22, 0x33, 0x44 };
+ var fbs = io.fixedBufferStream(payload);
+ const reader = fbs.reader();
+ var d = decoder(testing.allocator, reader);
+ defer d.deinit();
+ const val = try d.decode([]const u8);
+ try expectEqual(@as(usize, 0x11), val[0]);
+ try expectEqual(@as(usize, 0x22), val[1]);
+ try expectEqual(@as(usize, 0x33), val[2]);
+ try expectEqual(@as(usize, 0x44), val[3]);
+}