@@ -241,4 +241,103 @@ chain := SChain(
241241)
242242
243243err := ValidateBuffer (actual, chain)
244- ```
244+ ```
245+
246+
247+ ``` go
248+ // Build packed tuple: (42, "alpha", true, false, true)
249+ actual := pack.Pack (pack.PackTuple (
250+ pack.PackInt32 (42 ),
251+ pack.PackString (" alpha" ),
252+ pack.PackBool (true ),
253+ pack.PackBool (false ),
254+ pack.PackBool (true ),
255+ ))
256+
257+ // Strict schema: repeated field stays grouped
258+ chainStrict := SChain (
259+ STupleNamedVal (
260+ []string {" id" , " name" , " flags" },
261+ SInt32 ,
262+ SString ,
263+ SRepeat (1 , -1 , SBool ),
264+ ),
265+ )
266+
267+ // Flattened schema: repeated field expands inline
268+ chainFlat := SChain (
269+ STupleNamedValFlattened (
270+ []string {" id" , " name" , " flag" },
271+ SInt32 ,
272+ SString ,
273+ SRepeat (1 , -1 , SBool ),
274+ ),
275+ )
276+
277+ // Decode with strict schema
278+ decodedStrict , err := DecodeBuffer (actual, chainStrict)
279+ assert.NoError (t, err, " Strict named tuple decode should succeed" )
280+
281+ expectedStrict := map [string ]any{
282+ " id" : int32 (42 ),
283+ " name" : " alpha" ,
284+ " flags" : []any{true , false , true },
285+ }
286+ fmt.Println (" DecodedStrict:" , decodedStrict)
287+ // Decode with flattened schema
288+ decodedFlat , err := DecodeBuffer (actual, chainFlat)
289+
290+ expectedFlat := map [string ]any{
291+ " id" : int32 (42 ),
292+ " name" : " alpha" ,
293+ " flag_0" : true ,
294+ " flag_1" : false ,
295+ " flag_2" : true ,
296+ }
297+ fmt.Println (" DecodedFlat:" , decodedFlat)
298+ ```
299+
300+ ``` go
301+ // Define scheme in JSON form
302+ schemeJSON := SchemeJSON {
303+ Type : " repeat" ,
304+ Min : 1 ,
305+ Max : -1 ,
306+ Schema : []SchemeJSON {
307+ {
308+ Type: " tuple" ,
309+ Schema: []SchemeJSON{
310+ {Type: " int32" },
311+ {Type: " bool" },
312+ {Type: " string" },
313+ },
314+ },
315+ {
316+ Type: " tuple" ,
317+ Schema: []SchemeJSON{
318+ {Type: " int16" },
319+ {Type: " bool" },
320+ {Type: " string" },
321+ },
322+ },
323+ },
324+ }
325+
326+ // Build scheme from JSON
327+ built := BuildScheme (schemeJSON)
328+
329+ // Manually constructed scheme
330+ expected := SRepeat (1 , -1 ,
331+ STuple (
332+ SInt32 ,
333+ SBool ,
334+ SString ,
335+ ),
336+ STuple (
337+ SInt16 ,
338+ SBool ,
339+ SString ,
340+ ),
341+ )
342+
343+ ```
0 commit comments