@@ 60,3 60,26 @@ test "marshal value" {
try expectEqualSlices(u8, tuple[0], fbs.getWritten());
}
}
+
+test "marshal optional" {
+ {
+ var buf: [0x1_000]u8 = undefined;
+ var fbs = io.fixedBufferStream(&buf);
+ const writer = fbs.writer();
+ var e = encoder(writer);
+
+ const val: ?u32 = null;
+ try e.encode(val);
+ try expectEqualSlices(u8, &[_]u8{0x00}, fbs.getWritten());
+ }
+ {
+ var buf: [0x1_000]u8 = undefined;
+ var fbs = io.fixedBufferStream(&buf);
+ const writer = fbs.writer();
+ var e = encoder(writer);
+ const val: ?u32 = 0xDEADBEEF;
+
+ try e.encode(val);
+ try testing.expectEqualSlices(u8, &[_]u8{ 0x01, 0xEF, 0xBE, 0xAD, 0xDE }, fbs.getWritten());
+ }
+}