questdb-rs 6.1.0

QuestDB Client Library for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
/*******************************************************************************
 *     ___                  _   ____  ____
 *    / _ \ _   _  ___  ___| |_|  _ \| __ )
 *   | | | | | | |/ _ \/ __| __| | | |  _ \
 *   | |_| | |_| |  __/\__ \ |_| |_| | |_) |
 *    \__\_\\__,_|\___||___/\__|____/|____/
 *
 *  Copyright (c) 2014-2019 Appsicle
 *  Copyright (c) 2019-2025 QuestDB
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

use crate::ErrorCode;
use crate::ingress::{Buffer, DecimalView, ProtocolVersion};
use crate::tests::{TestResult, assert_err_contains};
use rstest::rstest;

fn serialize_decimal(decimal: DecimalView) -> Vec<u8> {
    let mut out = Vec::new();
    decimal.serialize(&mut out);
    out
}

// ============================================================================
// Tests for &str implementation
// ============================================================================

#[test]
fn test_str_positive_decimal() -> TestResult {
    let decimal = DecimalView::try_new_string("123.45")?;
    let result = serialize_decimal(decimal);
    assert_eq!(result, b"123.45d");
    Ok(())
}

#[test]
fn test_str_negative_decimal() -> TestResult {
    let decimal = DecimalView::try_new_string("-123.45")?;
    let result = serialize_decimal(decimal);
    assert_eq!(result, b"-123.45d");
    Ok(())
}

#[test]
fn test_str_zero() -> TestResult {
    let decimal = DecimalView::try_new_string("0")?;
    let result = serialize_decimal(decimal);
    assert_eq!(result, b"0d");
    Ok(())
}

#[test]
fn test_str_nan() -> TestResult {
    let decimal = DecimalView::try_new_string("NaN")?;
    let result = serialize_decimal(decimal);
    assert_eq!(result, b"NaNd");
    Ok(())
}

#[test]
fn test_str_inf() -> TestResult {
    let decimal = DecimalView::try_new_string("Infinity")?;
    let result = serialize_decimal(decimal);
    assert_eq!(result, b"Infinityd");
    Ok(())
}

#[test]
fn test_str_negative_infinity() -> TestResult {
    let decimal = DecimalView::try_new_string("-Infinity")?;
    let result = serialize_decimal(decimal);
    assert_eq!(result, b"-Infinityd");
    Ok(())
}

#[test]
fn test_str_scientific_notation() -> TestResult {
    let decimal = DecimalView::try_new_string("1.5e-3")?;
    let result = serialize_decimal(decimal);
    assert_eq!(result, b"1.5e-3d");
    Ok(())
}

#[test]
fn test_str_large_decimal() -> TestResult {
    let decimal = DecimalView::try_new_string("999999999999999999.123456789")?;
    let result = serialize_decimal(decimal);
    assert_eq!(result, b"999999999999999999.123456789d");
    Ok(())
}

#[test]
fn test_str_with_leading_zero() -> TestResult {
    let decimal = DecimalView::try_new_string("0.001")?;
    let result = serialize_decimal(decimal);
    assert_eq!(result, b"0.001d");
    Ok(())
}

#[test]
fn test_str_rejects_space() -> TestResult {
    let result = DecimalView::try_new_string("12 3.45");
    assert_err_contains(result, ErrorCode::InvalidDecimal, "reserved character");
    Ok(())
}

#[test]
fn test_str_rejects_comma() -> TestResult {
    let result = DecimalView::try_new_string("1,234.56");
    assert_err_contains(result, ErrorCode::InvalidDecimal, "reserved character");
    Ok(())
}

#[test]
fn test_str_rejects_equals() -> TestResult {
    let result = DecimalView::try_new_string("123=45");
    assert_err_contains(result, ErrorCode::InvalidDecimal, "reserved character");
    Ok(())
}

#[test]
fn test_str_rejects_newline() -> TestResult {
    let result = DecimalView::try_new_string("123\n45");
    assert_err_contains(result, ErrorCode::InvalidDecimal, "reserved character");
    Ok(())
}

#[test]
fn test_str_rejects_backslash() -> TestResult {
    let result = DecimalView::try_new_string("123\\45");
    assert_err_contains(result, ErrorCode::InvalidDecimal, "reserved character");
    Ok(())
}

/// Validates the binary format structure and extracts the components.
#[cfg(any(feature = "rust_decimal", feature = "bigdecimal"))]
fn parse_binary_decimal(bytes: &[u8]) -> (u8, i128) {
    // Validate format markers

    use crate::ingress::DECIMAL_BINARY_FORMAT_TYPE;
    assert_eq!(bytes[0], b'=', "Missing binary format marker");
    assert_eq!(
        bytes[1], DECIMAL_BINARY_FORMAT_TYPE,
        "Invalid decimal type byte"
    );

    let scale = bytes[2];
    let length = bytes[3] as usize;

    assert!(scale <= 76, "Scale {} exceeds maximum of 76", scale);
    assert_eq!(
        bytes.len(),
        4 + length,
        "Binary data length mismatch: expected {} bytes, got {}",
        4 + length,
        bytes.len()
    );

    // Parse mantissa bytes as big-endian two's complement
    let mantissa_bytes = &bytes[4..];

    // Convert from big-endian bytes to i128
    // We need to sign-extend if the value is negative (high bit set)
    let mut i128_bytes = [0u8; 16];
    let offset = 16 - length;

    // Copy mantissa bytes to the lower part of i128_bytes
    i128_bytes[offset..].copy_from_slice(mantissa_bytes);

    // Sign extend if negative (check if high bit of mantissa is set)
    if mantissa_bytes[0] & 0x80 != 0 {
        // Fill upper bytes with 0xFF for negative numbers
        i128_bytes[..offset].fill(0xFF);
    }

    let unscaled = i128::from_be_bytes(i128_bytes);

    (scale, unscaled)
}

// ============================================================================
// Tests for rust_decimal::Decimal implementation
// ============================================================================

#[cfg(feature = "rust_decimal")]
mod rust_decimal_tests {
    use super::*;
    use crate::ingress::DecimalView;
    use rust_decimal::Decimal;
    use std::convert::TryInto;
    use std::str::FromStr;

    #[test]
    fn test_decimal_binary_format_zero() -> TestResult {
        let dec = Decimal::ZERO;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 0, "Zero should have scale 0");
        assert_eq!(unscaled, 0, "Zero should have unscaled value 0");
        Ok(())
    }

    #[test]
    fn test_decimal_binary_format_positive() -> TestResult {
        let dec = Decimal::from_str("123.45")?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 2, "123.45 should have scale 2");
        assert_eq!(unscaled, 12345, "123.45 should have unscaled value 12345");
        Ok(())
    }

    #[test]
    fn test_decimal_binary_format_negative() -> TestResult {
        let dec = Decimal::from_str("-123.45")?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 2, "-123.45 should have scale 2");
        assert_eq!(
            unscaled, -12345,
            "-123.45 should have unscaled value -12345"
        );
        Ok(())
    }

    #[test]
    fn test_decimal_binary_format_one() -> TestResult {
        let dec = Decimal::ONE;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 0, "One should have scale 0");
        assert_eq!(unscaled, 1, "One should have unscaled value 1");
        Ok(())
    }

    #[test]
    fn test_decimal_binary_format_max_scale() -> TestResult {
        // Create a decimal with maximum scale (28 for rust_decimal)
        let dec = Decimal::from_str("0.0000000000000000000000000001")?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 28, "Should have maximum scale of 28");
        assert_eq!(unscaled, 1, "Should have unscaled value 1");
        Ok(())
    }

    #[test]
    fn test_decimal_binary_format_large_value() -> TestResult {
        let dec = Decimal::MAX;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 0, "Large integer should have scale 0");
        assert_eq!(
            unscaled, 79228162514264337593543950335i128,
            "Should have correct unscaled value"
        );
        Ok(())
    }

    #[test]
    fn test_decimal_binary_format_large_value2() -> TestResult {
        let dec = Decimal::MIN;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 0, "Large integer should have scale 0");
        assert_eq!(
            unscaled, -79228162514264337593543950335i128,
            "Should have correct unscaled value"
        );
        Ok(())
    }

    #[test]
    fn test_decimal_binary_format_small_negative() -> TestResult {
        let dec = Decimal::from_str("-0.01")?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 2, "-0.01 should have scale 2");
        assert_eq!(unscaled, -1, "-0.01 should have unscaled value -1");
        Ok(())
    }

    #[test]
    fn test_decimal_binary_format_trailing_zeros() -> TestResult {
        let dec = Decimal::from_str("1.00")?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        // rust_decimal normalizes trailing zeros
        assert_eq!(scale, 2, "1.00 should have scale 2");
        assert_eq!(unscaled, 100, "1.00 should have unscaled value 100");
        Ok(())
    }
}

// ============================================================================
// Tests for bigdecimal::BigDecimal implementation
// ============================================================================

#[cfg(feature = "bigdecimal")]
mod bigdecimal_tests {
    use super::*;
    use crate::ingress::DecimalView;
    use bigdecimal::BigDecimal;
    use std::convert::TryInto;
    use std::str::FromStr;

    #[test]
    fn test_bigdecimal_binary_format_zero() -> TestResult {
        let dec = BigDecimal::from_str("0")?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 0, "Zero should have scale 0");
        assert_eq!(unscaled, 0, "Zero should have unscaled value 0");
        Ok(())
    }

    #[test]
    fn test_bigdecimal_binary_format_positive() -> TestResult {
        let dec = BigDecimal::from_str("123.45")?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 2, "123.45 should have scale 2");
        assert_eq!(unscaled, 12345, "123.45 should have unscaled value 12345");
        Ok(())
    }

    #[test]
    fn test_bigdecimal_binary_format_negative() -> TestResult {
        let dec = BigDecimal::from_str("-123.45")?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 2, "-123.45 should have scale 2");
        assert_eq!(
            unscaled, -12345,
            "-123.45 should have unscaled value -12345"
        );
        Ok(())
    }

    #[test]
    fn test_bigdecimal_binary_format_one() -> TestResult {
        let dec = BigDecimal::from_str("1")?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 0, "One should have scale 0");
        assert_eq!(unscaled, 1, "One should have unscaled value 1");
        Ok(())
    }

    #[test]
    fn test_bigdecimal_binary_format_high_precision() -> TestResult {
        // BigDecimal can handle arbitrary precision, test a value with many decimal places
        let dec = BigDecimal::from_str("0.123456789012345678901234567890")?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 30, "Should preserve high precision scale");
        assert_eq!(
            unscaled, 123456789012345678901234567890i128,
            "Should have correct unscaled value"
        );
        Ok(())
    }

    #[test]
    fn test_bigdecimal_binary_format_large_value() -> TestResult {
        // Test a very large value that BigDecimal can represent
        let dec = BigDecimal::from_str("79228162514264337593543950335")?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 0, "Large integer should have scale 0");
        assert_eq!(
            unscaled, 79228162514264337593543950335i128,
            "Should have correct unscaled value"
        );
        Ok(())
    }

    #[test]
    fn test_bigdecimal_binary_format_large_negative() -> TestResult {
        let dec = BigDecimal::from_str("-79228162514264337593543950335")?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 0, "Large negative integer should have scale 0");
        assert_eq!(
            unscaled, -79228162514264337593543950335i128,
            "Should have correct unscaled value"
        );
        Ok(())
    }

    #[test]
    fn test_bigdecimal_binary_format_small_negative() -> TestResult {
        let dec = BigDecimal::from_str("-0.01")?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 2, "-0.01 should have scale 2");
        assert_eq!(unscaled, -1, "-0.01 should have unscaled value -1");
        Ok(())
    }

    #[test]
    fn test_bigdecimal_binary_format_trailing_zeros() -> TestResult {
        let dec = BigDecimal::from_str("1.00")?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        // BigDecimal may normalize trailing zeros differently than rust_decimal
        assert_eq!(scale, 2, "1.00 should have scale 2");
        assert_eq!(unscaled, 100, "1.00 should have unscaled value 100");
        Ok(())
    }

    #[test]
    fn test_bigdecimal_binary_format_max_scale() -> TestResult {
        // Test with scale at QuestDB's limit of 76
        let dec = BigDecimal::from_str(
            "0.0000000000000000000000000000000000000000000000000000000000000000000000000001",
        )?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        assert_eq!(scale, 76, "Should have maximum scale of 76");
        assert_eq!(unscaled, 1, "Should have unscaled value 1");
        Ok(())
    }

    #[test]
    fn test_bigdecimal_binary_format_exceeds_max_scale() -> TestResult {
        // Test that exceeding scale 76 returns an error
        let dec = BigDecimal::from_str(
            "0.00000000000000000000000000000000000000000000000000000000000000000000000000001",
        )?;
        let result: crate::Result<DecimalView> = (&dec).try_into();
        assert_err_contains(result, ErrorCode::InvalidDecimal, "scale greater than 76");
        Ok(())
    }

    #[test]
    fn test_bigdecimal_binary_negative_scale() -> TestResult {
        // Test with a negative scale
        let dec = BigDecimal::from_str("1.23e12")?;
        let ilp_dec: DecimalView = (&dec).try_into()?;
        let result = serialize_decimal(ilp_dec);

        let (scale, unscaled) = parse_binary_decimal(&result);
        // QuestDB does not support negative scale, instead the value should be
        // scaled properly
        assert_eq!(scale, 0, "Should have scale of 0");
        assert_eq!(
            unscaled, 1230000000000,
            "Should have unscaled value 1230000000000"
        );
        Ok(())
    }

    #[test]
    fn test_bigdecimal_binary_value_too_large() -> TestResult {
        // QuestDB cannot accept arrays that are larger than what an i8 can fit
        let dec = BigDecimal::from_str("1e1000")?;
        let result: crate::Result<DecimalView> = (&dec).try_into();
        assert_err_contains(result, ErrorCode::InvalidDecimal, "decimal longer than");
        Ok(())
    }
}

// ============================================================================
// Buffer integration tests
// ============================================================================

#[rstest]
fn test_buffer_column_decimal_str(
    #[values(ProtocolVersion::V3)] version: ProtocolVersion,
) -> TestResult {
    let mut buffer = Buffer::new(version);
    buffer
        .table("test")?
        .symbol("sym", "val")?
        .column_dec("dec", "123.45")?
        .at_now()?;

    let output = std::str::from_utf8(buffer.as_bytes())?;
    assert!(output.starts_with("test,sym=val dec=123.45d"));
    Ok(())
}

#[rstest]
fn test_buffer_column_decimal_str_unsupported(
    #[values(ProtocolVersion::V1, ProtocolVersion::V2)] version: ProtocolVersion,
) -> TestResult {
    let mut buffer = Buffer::new(version);
    let result = buffer
        .table("test")?
        .symbol("sym", "val")?
        .column_dec("dec", "123.45");
    assert_err_contains(
        result,
        ErrorCode::ProtocolVersionError,
        "does not support the decimal datatype",
    );
    Ok(())
}

#[cfg(feature = "rust_decimal")]
#[test]
fn test_buffer_column_decimal_rust_decimal() -> TestResult {
    use rust_decimal::Decimal;
    use std::str::FromStr;

    let mut buffer = Buffer::new(ProtocolVersion::V3);
    let dec = Decimal::from_str("123.45")?;
    buffer
        .table("test")?
        .symbol("sym", "val")?
        .column_dec("dec", &dec)?
        .at_now()?;

    let bytes = buffer.as_bytes();
    // Should start with table name and symbol
    assert!(bytes.starts_with(b"test,sym=val dec="));
    assert!(bytes.ends_with(b"\n"));

    // Skip the prefix and \n suffix
    let dec_binary = &bytes[17..bytes.len() - 1];
    let (scale, unscaled) = parse_binary_decimal(dec_binary);
    assert_eq!(scale, 2, "123.45 should have scale 2");
    assert_eq!(unscaled, 12345, "123.45 should have unscaled value 12345");
    Ok(())
}

#[test]
fn test_buffer_multiple_decimals() -> TestResult {
    let mut buffer = Buffer::new(ProtocolVersion::V3);
    buffer
        .table("test")?
        .column_dec("dec1", "123.45")?
        .column_dec("dec2", "-67.89")?
        .column_dec("dec3", "0.001")?
        .at_now()?;

    let output = std::str::from_utf8(buffer.as_bytes())?;
    assert!(output.contains("dec1=123.45d"));
    assert!(output.contains("dec2=-67.89d"));
    assert!(output.contains("dec3=0.001d"));
    Ok(())
}

#[test]
fn test_decimal_column_name_too_long() -> TestResult {
    let mut buffer = Buffer::with_max_name_len(ProtocolVersion::V3, 4);
    let name = "a name too long";
    let err = buffer.table("tbl")?.column_dec(name, "123.45").unwrap_err();
    assert_eq!(err.code(), ErrorCode::InvalidName);
    assert_eq!(
        err.msg(),
        r#"Bad name: "a name too long": Too long (max 4 characters)"#
    );
    Ok(())
}

#[cfg(feature = "bigdecimal")]
#[test]
fn test_buffer_column_decimal_bigdecimal() -> TestResult {
    use bigdecimal::BigDecimal;
    use std::str::FromStr;

    let mut buffer = Buffer::new(ProtocolVersion::V3);
    let dec = BigDecimal::from_str("123.45")?;
    buffer
        .table("test")?
        .symbol("sym", "val")?
        .column_dec("dec", &dec)?
        .at_now()?;

    let bytes = buffer.as_bytes();
    // Should start with table name and symbol
    assert!(bytes.starts_with(b"test,sym=val dec="));
    assert!(bytes.ends_with(b"\n"));

    // Skip the prefix and \n suffix
    let dec_binary = &bytes[17..bytes.len() - 1];
    let (scale, unscaled) = parse_binary_decimal(dec_binary);
    assert_eq!(scale, 2, "123.45 should have scale 2");
    assert_eq!(unscaled, 12345, "123.45 should have unscaled value 12345");
    Ok(())
}