(t *testing.T)
| 410 | } |
| 411 | |
| 412 | func TestBulkFlagNoVariable(t *testing.T) { |
| 413 | ctx := context.Background() |
| 414 | |
| 415 | // Test that bulkFlagNoVariable works correctly on decode with multiple records |
| 416 | // This flag indicates no variable-length section, so no 2-byte offset is present |
| 417 | // and no variable data (payload, flags, OLC) can be included |
| 418 | |
| 419 | templateBody := BulkBody{ |
| 420 | NoteFormat: BulkNoteFormatFlexNano, |
| 421 | NoteTemplate: `{"temp": 14.1, "humidity": 12, "pressure": 24}`, |
| 422 | } |
| 423 | templateJSON, err := note.JSONMarshal(templateBody) |
| 424 | require.NoError(t, err) |
| 425 | |
| 426 | // Test with THREE records - each with bulkFlagNoVariable flag set (0x80) |
| 427 | // Format per record: |
| 428 | // - uint8 header with bulkFlagNoVariable (0x80) |
| 429 | // - NO uint16 offset (since NO_VARIABLE flag is set) |
| 430 | // - float32 temp value (4 bytes) |
| 431 | // - int16 humidity value (2 bytes) |
| 432 | // - uint32 pressure value (4 bytes) |
| 433 | |
| 434 | binaryData := []byte{ |
| 435 | // Record 1 |
| 436 | 0x80, // Header: bulkFlagNoVariable (0x80) - no variable section |
| 437 | // No offset bytes here due to NO_VARIABLE flag |
| 438 | 0x66, 0x66, 0x16, 0x41, // float32: 9.4 (temp) |
| 439 | 0x2A, 0x00, // int16: 42 (humidity) |
| 440 | 0x01, 0x02, 0x03, 0x04, // uint32: 0x04030201 = 67305985 (pressure) |
| 441 | |
| 442 | // Record 2 |
| 443 | 0x80, // Header: bulkFlagNoVariable (0x80) - no variable section |
| 444 | 0x00, 0x00, 0x20, 0x41, // float32: 10.0 (temp) |
| 445 | 0x15, 0x00, // int16: 21 (humidity) |
| 446 | 0x05, 0x06, 0x07, 0x08, // uint32: 0x08070605 = 134678021 (pressure) |
| 447 | |
| 448 | // Record 3 |
| 449 | 0x80, // Header: bulkFlagNoVariable (0x80) - no variable section |
| 450 | 0xCD, 0xCC, 0x4C, 0x40, // float32: 3.2 (temp) |
| 451 | 0x64, 0x00, // int16: 100 (humidity) |
| 452 | 0xFF, 0xFF, 0xFF, 0xFF, // uint32: 0xFFFFFFFF = 4294967295 (pressure) |
| 453 | } |
| 454 | |
| 455 | // Test decoding all three records |
| 456 | decodeCtx, err := BulkDecodeTemplate(ctx, templateJSON, binaryData) |
| 457 | require.NoError(t, err) |
| 458 | |
| 459 | // Expected values for each record |
| 460 | expectedRecords := []struct { |
| 461 | temp float64 |
| 462 | humidity float64 |
| 463 | pressure float64 |
| 464 | }{ |
| 465 | {9.4, 42, 67305985}, |
| 466 | {10.0, 21, 134678021}, |
| 467 | {3.2, 100, 4294967295}, |
| 468 | } |
| 469 |
nothing calls this directly
no test coverage detected