@@ -160,7 +160,7 @@ test "array and slice format customizations" {
160
160
161
161
const format_as_bin : lizpack .FormatOptions (@TypeOf (my_string )) = .bin ;
162
162
const slice = try lizpack .encode (my_string , & out , .{ .format = format_as_bin });
163
- try std .testing .expectEqualSlices (u8 , &.{ (lizpack.Spec .Format { .bin_8 = {} }).encode (), 3 , 'f' , 'o' , 'o' }, slice );
163
+ try std .testing .expectEqualSlices (u8 , &.{ (lizpack.spec .Format { .bin_8 = {} }).encode (), 3 , 'f' , 'o' , 'o' }, slice );
164
164
165
165
const format_as_string : lizpack .FormatOptions (@TypeOf (my_string )) = .str ;
166
166
const slice2 = try lizpack .encode (my_string , & out , .{ .format = format_as_string });
@@ -169,12 +169,12 @@ test "array and slice format customizations" {
169
169
const format_as_array : lizpack .FormatOptions (@TypeOf (my_string )) = .array ;
170
170
const slice3 = try lizpack .encode (my_string , & out , .{ .format = format_as_array });
171
171
try std .testing .expectEqualSlices (u8 , &.{
172
- (lizpack.Spec .Format { .fixarray = .{ .len = 3 } }).encode (),
173
- (lizpack.Spec .Format { .uint_8 = {} }).encode (),
172
+ (lizpack.spec .Format { .fixarray = .{ .len = 3 } }).encode (),
173
+ (lizpack.spec .Format { .uint_8 = {} }).encode (),
174
174
'f' ,
175
- (lizpack.Spec .Format { .uint_8 = {} }).encode (),
175
+ (lizpack.spec .Format { .uint_8 = {} }).encode (),
176
176
'o' ,
177
- (lizpack.Spec .Format { .uint_8 = {} }).encode (),
177
+ (lizpack.spec .Format { .uint_8 = {} }).encode (),
178
178
'o' ,
179
179
}, slice3 );
180
180
}
@@ -188,12 +188,12 @@ test "union format customization" {
188
188
pub const format_as_active_field : lizpack .FormatOptions (@This ()) = .{ .layout = .active_field };
189
189
};
190
190
191
- const bytes_active_field : []const u8 = &.{(lizpack.Spec .Format { .false = {} }).encode ()};
191
+ const bytes_active_field : []const u8 = &.{(lizpack.spec .Format { .false = {} }).encode ()};
192
192
try std .testing .expectEqual (MyUnion { .my_bool = false }, try lizpack .decode (MyUnion , bytes_active_field , .{ .format = MyUnion .format_as_active_field }));
193
193
194
194
const bytes_map : []const u8 = &.{
195
- (lizpack.Spec .Format { .fixmap = .{ .n_elements = 1 } }).encode (),
196
- (lizpack.Spec .Format { .fixstr = .{ .len = 5 } }).encode (),
195
+ (lizpack.spec .Format { .fixmap = .{ .n_elements = 1 } }).encode (),
196
+ (lizpack.spec .Format { .fixstr = .{ .len = 5 } }).encode (),
197
197
'm' ,
198
198
'y' ,
199
199
'_' ,
@@ -219,15 +219,15 @@ test "maps" {
219
219
const format : lizpack .FormatOptions (@TypeOf (roles )) = .{ .layout = .map_item_first_field_is_key };
220
220
221
221
const expected_bytes : []const u8 = &.{
222
- (lizpack.Spec .Format { .fixmap = .{ .n_elements = 2 } }).encode (),
223
- (lizpack.Spec .Format { .fixstr = .{ .len = 5 } }).encode (),
222
+ (lizpack.spec .Format { .fixmap = .{ .n_elements = 2 } }).encode (),
223
+ (lizpack.spec .Format { .fixstr = .{ .len = 5 } }).encode (),
224
224
's' ,
225
225
'a' ,
226
226
'r' ,
227
227
'a' ,
228
228
'h' ,
229
229
0 ,
230
- (lizpack.Spec .Format { .fixstr = .{ .len = 3 } }).encode (),
230
+ (lizpack.spec .Format { .fixstr = .{ .len = 3 } }).encode (),
231
231
'b' ,
232
232
'o' ,
233
233
'b' ,
@@ -246,3 +246,26 @@ test "encodeAlloc" {
246
246
try std .testing .expectEqual (@as (usize , 12 ), slice .len );
247
247
try std .testing .expectEqual (expected , lizpack .decode (@TypeOf (expected ), slice , .{}));
248
248
}
249
+
250
+ test "manual encoding" {
251
+ const expected : []const u8 = &.{
252
+ (lizpack.spec.Format { .fixstr = .{ .len = 3 } }).encode (),
253
+ 'f' ,
254
+ 'o' ,
255
+ 'o' ,
256
+ };
257
+ const actual : lizpack.manual.MessagePackType = .{ .fixstr = "foo" };
258
+ const encoded = try lizpack .manual .encodeAlloc (std .testing .allocator , actual );
259
+ defer std .testing .allocator .free (encoded );
260
+ try std .testing .expectEqualSlices (u8 , expected , encoded );
261
+ }
262
+
263
+ test "manual decoding" {
264
+ const raw : []const u8 = &.{@bitCast (@as (i8 , -15 ))};
265
+ const decoded = try lizpack .manual .decodeAlloc (std .testing .allocator , raw );
266
+ defer decoded .deinit ();
267
+ switch (decoded .value ) {
268
+ .negative_fixint = > | payload | try std .testing .expectEqual (-15 , payload ),
269
+ else = > return error .Invalid ,
270
+ }
271
+ }
0 commit comments