1use crate::SmartString;
127use crate::error::{CommonError, Result};
128use serde::{Deserialize, Serialize};
129use simd_json::{BorrowedValue, OwnedValue, to_borrowed_value};
130use smallvec::SmallVec;
131use std::cell::RefCell;
132use std::fmt;
133use std::fmt::Write;
134
135pub struct UnifiedBufferManager {
162 text_buffer: Vec<u8>,
164 binary_buffer: Vec<u8>,
165
166 json_parse_buffer: Vec<u8>,
168 json_serialize_buffer: Vec<u8>,
169 json_large_buffer: Vec<u8>,
170
171 string_format_buffer: String,
173}
174
175impl Default for UnifiedBufferManager {
176 fn default() -> Self {
177 Self::new()
178 }
179}
180
181impl UnifiedBufferManager {
182 pub fn new() -> Self {
184 Self {
185 text_buffer: Vec::with_capacity(8192), binary_buffer: Vec::with_capacity(65536), json_parse_buffer: Vec::with_capacity(8192), json_serialize_buffer: Vec::with_capacity(4096), json_large_buffer: Vec::with_capacity(65536), string_format_buffer: String::with_capacity(256), }
192 }
193
194 pub fn text_buffer_mut(&mut self) -> &mut Vec<u8> {
197 self.text_buffer.clear();
198 &mut self.text_buffer
199 }
200
201 pub fn binary_buffer_mut(&mut self) -> &mut Vec<u8> {
203 self.binary_buffer.clear();
204 &mut self.binary_buffer
205 }
206
207 pub fn json_parse_buffer_mut(&mut self) -> &mut Vec<u8> {
210 self.json_parse_buffer.clear();
211 &mut self.json_parse_buffer
212 }
213
214 pub fn json_serialize_buffer_mut(&mut self) -> &mut Vec<u8> {
216 self.json_serialize_buffer.clear();
217 &mut self.json_serialize_buffer
218 }
219
220 pub fn json_large_buffer_mut(&mut self) -> &mut Vec<u8> {
222 self.json_large_buffer.clear();
223 &mut self.json_large_buffer
224 }
225
226 pub fn string_format_buffer_mut(&mut self) -> &mut String {
228 self.string_format_buffer.clear();
229 &mut self.string_format_buffer
230 }
231
232 pub fn process_with_text_buffer<F, R>(&mut self, processor: F) -> R
235 where
236 F: FnOnce(&mut Vec<u8>) -> R,
237 {
238 let buffer = self.text_buffer_mut();
239 processor(buffer)
240 }
241
242 pub fn process_with_binary_buffer<F, R>(&mut self, processor: F) -> R
244 where
245 F: FnOnce(&mut Vec<u8>) -> R,
246 {
247 let buffer = self.binary_buffer_mut();
248 processor(buffer)
249 }
250
251 pub fn process_with_json_buffer<F, R>(&mut self, processor: F) -> R
253 where
254 F: FnOnce(&mut Vec<u8>) -> R,
255 {
256 let buffer = self.json_parse_buffer_mut();
257 processor(buffer)
258 }
259
260 pub const fn get_stats(&self) -> UnifiedBufferStats {
262 UnifiedBufferStats {
263 text_buffer_capacity: self.text_buffer.capacity(),
264 binary_buffer_capacity: self.binary_buffer.capacity(),
265 json_parse_buffer_capacity: self.json_parse_buffer.capacity(),
266 json_serialize_buffer_capacity: self.json_serialize_buffer.capacity(),
267 json_large_buffer_capacity: self.json_large_buffer.capacity(),
268 string_format_buffer_capacity: self.string_format_buffer.capacity(),
269 text_buffer_len: self.text_buffer.len(),
270 binary_buffer_len: self.binary_buffer.len(),
271 json_parse_buffer_len: self.json_parse_buffer.len(),
272 json_serialize_buffer_len: self.json_serialize_buffer.len(),
273 json_large_buffer_len: self.json_large_buffer.len(),
274 string_format_buffer_len: self.string_format_buffer.len(),
275 }
276 }
277}
278
279#[derive(Debug, Clone)]
281pub struct UnifiedBufferStats {
282 pub text_buffer_capacity: usize,
284 pub binary_buffer_capacity: usize,
286 pub json_parse_buffer_capacity: usize,
288 pub json_serialize_buffer_capacity: usize,
290 pub json_large_buffer_capacity: usize,
292 pub string_format_buffer_capacity: usize,
294 pub text_buffer_len: usize,
296 pub binary_buffer_len: usize,
298 pub json_parse_buffer_len: usize,
300 pub json_serialize_buffer_len: usize,
302 pub json_large_buffer_len: usize,
304 pub string_format_buffer_len: usize,
306}
307
308thread_local! {
309 static UNIFIED_BUFFER_MANAGER: RefCell<UnifiedBufferManager> =
310 RefCell::new(UnifiedBufferManager::new());
311}
312
313pub fn with_unified_buffer_manager<F, R>(processor: F) -> R
315where
316 F: FnOnce(&mut UnifiedBufferManager) -> R,
317{
318 UNIFIED_BUFFER_MANAGER.with(|manager| {
319 let mut manager = manager.borrow_mut();
320 processor(&mut manager)
321 })
322}
323
324#[derive(Debug, Clone)]
330pub struct ZeroCopySlice<'a, T> {
331 data: &'a [T],
332 len: usize,
333}
334
335impl<'a, T> ZeroCopySlice<'a, T> {
336 #[inline(always)]
338 pub fn new(data: &'a [T], len: usize) -> Self {
339 Self {
340 data,
341 len: len.min(data.len()),
342 }
343 }
344
345 #[inline(always)]
347 pub fn as_slice(&self) -> &'a [T] {
348 &self.data[..self.len]
349 }
350
351 #[inline(always)]
353 pub const fn len(&self) -> usize {
354 self.len
355 }
356
357 #[inline(always)]
359 pub const fn is_empty(&self) -> bool {
360 self.len == 0
361 }
362}
363
364pub struct ZeroCopyMessage<'a> {
366 payload: &'a [u8],
367 processed: bool,
368}
369
370impl<'a> ZeroCopyMessage<'a> {
371 #[inline(always)]
373 pub const fn new(payload: &'a [u8]) -> Self {
374 Self {
375 payload,
376 processed: false,
377 }
378 }
379
380 #[inline(always)]
382 pub const fn as_bytes(&self) -> &'a [u8] {
383 self.payload
384 }
385
386 #[inline(always)]
388 pub const fn as_str(&self) -> std::result::Result<&'a str, std::str::Utf8Error> {
389 std::str::from_utf8(self.payload)
390 }
391
392 #[inline(always)]
394 pub const fn len(&self) -> usize {
395 self.payload.len()
396 }
397
398 #[inline(always)]
400 pub const fn is_empty(&self) -> bool {
401 self.payload.is_empty()
402 }
403
404 #[inline(always)]
406 pub const fn mark_processed(&mut self) {
407 self.processed = true;
408 }
409
410 #[inline(always)]
412 pub const fn is_processed(&self) -> bool {
413 self.processed
414 }
415}
416
417pub struct UnifiedStringUtils;
423
424impl UnifiedStringUtils {
425 #[inline(always)]
427 fn create_prefixed_id(prefix: &str, order_id: &impl fmt::Display) -> SmartString {
428 let mut result = SmartString::new();
429 write!(result, "{prefix}_{order_id}").expect("Failed to format prefixed ID");
430 result
431 }
432
433 #[inline(always)]
435 pub fn create_rejection_id(order_id: &impl fmt::Display) -> SmartString {
436 Self::create_prefixed_id("rej", order_id)
437 }
438
439 #[inline(always)]
441 pub fn create_execution_id(order_id: &impl fmt::Display) -> SmartString {
442 Self::create_prefixed_id("exec", order_id)
443 }
444
445 #[inline(always)]
447 pub fn create_cancellation_id(order_id: &impl fmt::Display) -> SmartString {
448 Self::create_prefixed_id("cancel", order_id)
449 }
450
451 #[inline(always)]
453 pub fn error_to_smart_string(error: &impl fmt::Display) -> SmartString {
454 let mut result = SmartString::new();
455 write!(result, "{error}").expect("Failed to format error to SmartString");
456 result
457 }
458
459 #[inline(always)]
461 pub fn display_to_smart_string(value: &impl fmt::Display) -> SmartString {
462 let mut result = SmartString::new();
463 write!(result, "{value}").expect("Failed to format display value to SmartString");
464 result
465 }
466
467 pub fn create_rejection_id_buffered(order_id: &impl fmt::Display) -> SmartString {
469 with_unified_buffer_manager(|manager| {
470 let buf = manager.string_format_buffer_mut();
471 write!(buf, "rej_{order_id}").expect("Failed to format rejection ID");
472 SmartString::from(buf.as_str())
473 })
474 }
475
476 pub fn create_execution_id_buffered(order_id: &impl fmt::Display) -> SmartString {
478 with_unified_buffer_manager(|manager| {
479 let buf = manager.string_format_buffer_mut();
480 write!(buf, "exec_{order_id}").expect("Failed to format execution ID");
481 SmartString::from(buf.as_str())
482 })
483 }
484}
485
486pub struct ZeroCopyCollections;
492
493impl ZeroCopyCollections {
494 #[inline(always)]
496 pub fn small_vec<T, const N: usize>() -> SmallVec<[T; N]> {
497 SmallVec::new()
498 }
499
500 #[inline(always)]
502 pub fn small_vec_with_capacity<T, const N: usize>(capacity: usize) -> SmallVec<[T; N]> {
503 SmallVec::with_capacity(capacity)
504 }
505
506 #[inline(always)]
508 pub fn slice_to_small_vec<T: Clone, const N: usize>(slice: &[T]) -> SmallVec<[T; N]> {
509 let mut result = SmallVec::new();
510 for item in slice {
511 result.push(item.clone());
512 }
513 result
514 }
515}
516
517pub struct ZeroCopyJson;
523
524impl ZeroCopyJson {
525 pub fn parse_from_slice<T>(input: &mut [u8]) -> Result<T>
530 where
531 T: for<'de> Deserialize<'de>,
532 {
533 simd_json::serde::from_slice(input)
534 .map_err(|e| CommonError::Parse(format!("Zero-copy JSON parse error: {e}").into()))
535 }
536
537 pub fn parse_from_str<T>(input: &str) -> Result<T>
542 where
543 T: for<'de> Deserialize<'de>,
544 {
545 with_unified_buffer_manager(|manager| {
546 let buf = manager.json_parse_buffer_mut();
547 buf.extend_from_slice(input.as_bytes());
548
549 simd_json::serde::from_slice(buf)
550 .map_err(|e| CommonError::Parse(format!("Buffered JSON parse error: {e}").into()))
551 })
552 }
553
554 pub fn parse_to_value(input: &mut [u8]) -> Result<OwnedValue> {
556 simd_json::from_slice(input)
557 .map_err(|e| CommonError::Parse(format!("Zero-copy value parse error: {e}").into()))
558 }
559
560 pub fn parse_to_borrowed_value<'a>(input: &'a mut [u8]) -> Result<BorrowedValue<'a>> {
566 to_borrowed_value(input)
567 .map_err(|e| CommonError::Parse(format!("Zero-copy borrowed parse error: {e}").into()))
568 }
569
570 pub fn parse_str_to_value(input: &str) -> Result<OwnedValue> {
572 with_unified_buffer_manager(|manager| {
573 let buf = manager.json_parse_buffer_mut();
574 buf.extend_from_slice(input.as_bytes());
575
576 simd_json::from_slice(buf)
577 .map_err(|e| CommonError::Parse(format!("Buffered value parse error: {e}").into()))
578 })
579 }
580
581 pub fn serialize_to_string<T>(value: &T) -> Result<SmartString>
583 where
584 T: Serialize,
585 {
586 with_unified_buffer_manager(|manager| {
587 let buf = manager.json_serialize_buffer_mut();
588
589 simd_json::serde::to_writer(&mut *buf, value)
590 .map_err(|e| CommonError::Json(format!("Zero-copy serialize error: {e}").into()))?;
591
592 let json_str = std::str::from_utf8(buf)
594 .map_err(|e| CommonError::Parse(format!("UTF-8 conversion error: {e}").into()))?;
595
596 Ok(SmartString::from(json_str))
597 })
598 }
599
600 pub fn serialize_to_bytes<T>(value: &T) -> Result<Vec<u8>>
602 where
603 T: Serialize,
604 {
605 with_unified_buffer_manager(|manager| {
606 let buf = manager.json_serialize_buffer_mut();
607
608 simd_json::serde::to_writer(&mut *buf, value)
609 .map_err(|e| CommonError::Json(format!("Zero-copy serialize error: {e}").into()))?;
610
611 Ok(std::mem::take(buf))
613 })
614 }
615
616 pub fn parse_multiple<T>(input: &mut [u8], delimiter: u8) -> Result<SmallVec<[T; 8]>>
621 where
622 T: for<'de> Deserialize<'de>,
623 {
624 let mut results = SmallVec::new();
625 let mut start = 0;
626 let len = input.len();
627
628 let mut positions = SmallVec::<[usize; 16]>::new();
630 for (i, &byte) in input.iter().enumerate() {
631 if byte == delimiter {
632 positions.push(i);
633 }
634 }
635
636 for &end in &positions {
638 if end > start {
639 let slice = &mut input[start..end];
640 if !slice.is_empty() && slice.iter().any(|&b| !b.is_ascii_whitespace()) {
641 let parsed: T = simd_json::serde::from_slice(slice).map_err(|e| {
642 CommonError::Parse(format!("Multi-parse error: {e}").into())
643 })?;
644 results.push(parsed);
645 }
646 }
647 start = end + 1;
648 }
649
650 if start < len {
652 let slice = &mut input[start..];
653 if !slice.is_empty() && slice.iter().any(|&b| !b.is_ascii_whitespace()) {
654 let parsed: T = simd_json::serde::from_slice(slice)
655 .map_err(|e| CommonError::Parse(format!("Multi-parse error: {e}").into()))?;
656 results.push(parsed);
657 }
658 }
659
660 Ok(results)
661 }
662}
663
664pub trait BorrowedValueExt {
670 fn get_str(&self, key: &str) -> Option<&str>;
672
673 fn get_u64(&self, key: &str) -> Option<u64>;
675
676 fn get_f64(&self, key: &str) -> Option<f64>;
678
679 fn get_bool(&self, key: &str) -> Option<bool>;
681}
682
683impl<'a> BorrowedValueExt for BorrowedValue<'a> {
684 #[inline]
685 fn get_str(&self, key: &str) -> Option<&str> {
686 use simd_json::prelude::*;
687 self.get(key)?.as_str()
688 }
689
690 #[inline]
691 fn get_u64(&self, key: &str) -> Option<u64> {
692 use simd_json::prelude::*;
693 self.get(key)?.as_u64()
694 }
695
696 #[inline]
697 fn get_f64(&self, key: &str) -> Option<f64> {
698 use simd_json::prelude::*;
699 self.get(key)?.as_f64()
700 }
701
702 #[inline]
703 fn get_bool(&self, key: &str) -> Option<bool> {
704 use simd_json::prelude::*;
705 self.get(key)?.as_bool()
706 }
707}
708
709pub struct WebSocketJsonZeroCopy;
715
716impl WebSocketJsonZeroCopy {
717 pub fn parse_websocket_message<T>(message_bytes: &mut [u8]) -> Result<T>
719 where
720 T: for<'de> Deserialize<'de>,
721 {
722 ZeroCopyJson::parse_from_slice(message_bytes)
723 }
724
725 pub fn parse_websocket_text<T>(message_text: &str) -> Result<T>
727 where
728 T: for<'de> Deserialize<'de>,
729 {
730 ZeroCopyJson::parse_from_str(message_text)
731 }
732
733 pub fn parse_to_borrowed<'a>(message_bytes: &'a mut [u8]) -> Result<BorrowedValue<'a>> {
735 ZeroCopyJson::parse_to_borrowed_value(message_bytes)
736 }
737
738 pub fn create_websocket_response<T>(value: &T) -> Result<SmartString>
740 where
741 T: Serialize,
742 {
743 ZeroCopyJson::serialize_to_string(value)
744 }
745
746 pub fn parse_multiple_messages<T>(buffer: &mut [u8]) -> Result<SmallVec<[T; 4]>>
748 where
749 T: for<'de> Deserialize<'de>,
750 {
751 let results: SmallVec<[T; 8]> = ZeroCopyJson::parse_multiple(buffer, b'\n')?;
752 let mut small_results = SmallVec::new();
753 for item in results {
754 small_results.push(item);
755 }
756 Ok(small_results)
757 }
758}
759
760pub struct ExchangeJsonZeroCopy;
766
767impl ExchangeJsonZeroCopy {
768 pub fn parse_api_response<T>(response_bytes: &mut [u8]) -> Result<T>
770 where
771 T: for<'de> Deserialize<'de>,
772 {
773 ZeroCopyJson::parse_from_slice(response_bytes)
774 }
775
776 pub fn parse_api_response_str<T>(response_text: &str) -> Result<T>
778 where
779 T: for<'de> Deserialize<'de>,
780 {
781 ZeroCopyJson::parse_from_str(response_text)
782 }
783
784 pub fn create_api_request<T>(request: &T) -> Result<SmartString>
786 where
787 T: Serialize,
788 {
789 ZeroCopyJson::serialize_to_string(request)
790 }
791
792 pub fn parse_orderbook_update<T>(data: &mut [u8]) -> Result<T>
794 where
795 T: for<'de> Deserialize<'de>,
796 {
797 simd_json::serde::from_slice(data)
798 .map_err(|e| CommonError::Parse(format!("OrderBook parse error: {e}").into()))
799 }
800
801 pub fn parse_trade_update<T>(data: &mut [u8]) -> Result<T>
803 where
804 T: for<'de> Deserialize<'de>,
805 {
806 simd_json::serde::from_slice(data)
807 .map_err(|e| CommonError::Parse(format!("Trade parse error: {e}").into()))
808 }
809}
810
811pub type ZeroCopyBufferManager = UnifiedBufferManager;
818pub type ZeroCopyStringUtils = UnifiedStringUtils;
820pub type BufferedStringOps = UnifiedStringUtils;
822pub type JsonBufferManager = UnifiedBufferManager;
824
825pub fn with_buffer_manager<F, R>(processor: F) -> R
827where
828 F: FnOnce(&mut UnifiedBufferManager) -> R,
829{
830 with_unified_buffer_manager(processor)
831}
832
833pub fn with_json_buffer_manager<F, R>(processor: F) -> R
835where
836 F: FnOnce(&mut UnifiedBufferManager) -> R,
837{
838 with_unified_buffer_manager(processor)
839}
840
841#[cfg(test)]
842mod tests {
843 use super::*;
844 use serde::{Deserialize, Serialize};
845 use simd_json::prelude::ValueObjectAccess;
846
847 #[derive(Debug, Serialize, Deserialize, PartialEq)]
848 struct TestOrder {
849 id: String,
850 symbol: String,
851 price: f64,
852 quantity: f64,
853 }
854
855 #[test]
856 fn test_unified_buffer_manager() {
857 with_unified_buffer_manager(|manager| {
858 let stats = manager.get_stats();
859 assert!(stats.text_buffer_capacity > 0);
860 assert!(stats.json_parse_buffer_capacity > 0);
861 assert!(stats.string_format_buffer_capacity > 0);
862 });
863 }
864
865 #[test]
866 fn test_zero_copy_slice() {
867 let data = [1, 2, 3, 4, 5];
868 let slice = ZeroCopySlice::new(&data, 3);
869
870 assert_eq!(slice.len(), 3);
871 assert_eq!(slice.as_slice(), &[1, 2, 3]);
872 assert!(!slice.is_empty());
873 }
874
875 #[test]
876 fn test_unified_string_utils() {
877 let order_id = "order_123";
878 let rejection_id = UnifiedStringUtils::create_rejection_id(&order_id);
879 assert_eq!(rejection_id, "rej_order_123");
880
881 let execution_id = UnifiedStringUtils::create_execution_id(&order_id);
882 assert_eq!(execution_id, "exec_order_123");
883
884 let cancellation_id = UnifiedStringUtils::create_cancellation_id(&order_id);
885 assert_eq!(cancellation_id, "cancel_order_123");
886 }
887
888 #[test]
889 fn test_buffered_string_operations() {
890 let order_id = "order_456";
891 let rejection_id = UnifiedStringUtils::create_rejection_id_buffered(&order_id);
892 assert_eq!(rejection_id, "rej_order_456");
893
894 let execution_id = UnifiedStringUtils::create_execution_id_buffered(&order_id);
895 assert_eq!(execution_id, "exec_order_456");
896 }
897
898 #[test]
899 fn test_zero_copy_message() {
900 let data = b"Hello, world!";
901 let mut message = ZeroCopyMessage::new(data);
902
903 assert_eq!(message.len(), 13);
904 assert!(!message.is_empty());
905 assert_eq!(message.as_bytes(), data);
906 assert_eq!(message.as_str().unwrap(), "Hello, world!");
907
908 assert!(!message.is_processed());
909 message.mark_processed();
910 assert!(message.is_processed());
911 }
912
913 #[test]
914 fn test_zero_copy_json_parse_from_slice() {
915 let json = r#"{"id":"order_123","symbol":"BTC-USDT","price":50000.0,"quantity":0.001}"#;
916 let mut bytes = json.as_bytes().to_vec();
917
918 let order: TestOrder = ZeroCopyJson::parse_from_slice(&mut bytes).unwrap();
919 assert_eq!(order.id, "order_123");
920 assert_eq!(order.symbol, "BTC-USDT");
921 assert_eq!(order.price, 50000.0);
922 assert_eq!(order.quantity, 0.001);
923 }
924
925 #[test]
926 fn test_zero_copy_json_parse_from_str() {
927 let json = r#"{"id":"order_456","symbol":"ETH-USDT","price":3000.0,"quantity":0.1}"#;
928
929 let order: TestOrder = ZeroCopyJson::parse_from_str(json).unwrap();
930 assert_eq!(order.id, "order_456");
931 assert_eq!(order.symbol, "ETH-USDT");
932 assert_eq!(order.price, 3000.0);
933 assert_eq!(order.quantity, 0.1);
934 }
935
936 #[test]
937 fn test_zero_copy_json_serialize() {
938 let order = TestOrder {
939 id: "order_789".to_string(),
940 symbol: "BTC-USDT".to_string(),
941 price: 45000.0,
942 quantity: 0.002,
943 };
944
945 let json = ZeroCopyJson::serialize_to_string(&order).unwrap();
946 assert!(json.contains("order_789"));
947 assert!(json.contains("BTC-USDT"));
948 }
949
950 #[test]
951 fn test_websocket_json_parsing() {
952 let json = r#"{"type":"order","data":{"id":"ws_order","symbol":"BTC-USDT","price":48000.0,"quantity":0.005}}"#;
953 let mut bytes = json.as_bytes().to_vec();
954
955 let value = ZeroCopyJson::parse_to_value(&mut bytes).unwrap();
956 assert!(value.get("type").is_some());
957 assert!(value.get("data").is_some());
958 }
959
960 #[test]
961 fn test_parse_multiple_json_objects() {
962 let json = r#"{"id":"order_1","symbol":"BTC-USDT","price":100.0,"quantity":1.0}
963{"id":"order_2","symbol":"ETH-USDT","price":200.0,"quantity":2.0}
964{"id":"order_3","symbol":"LTC-USDT","price":300.0,"quantity":3.0}"#;
965 let mut bytes = json.as_bytes().to_vec();
966
967 let orders: SmallVec<[TestOrder; 8]> =
968 ZeroCopyJson::parse_multiple(&mut bytes, b'\n').unwrap();
969 assert_eq!(orders.len(), 3);
970 assert_eq!(orders[0].id, "order_1");
971 assert_eq!(orders[0].symbol, "BTC-USDT");
972 assert_eq!(orders[1].price, 200.0);
973 assert_eq!(orders[1].symbol, "ETH-USDT");
974 assert_eq!(orders[2].id, "order_3");
975 assert_eq!(orders[2].symbol, "LTC-USDT");
976 }
977
978 #[test]
979 fn test_exchange_json_utilities() {
980 let json = r#"{"symbol":"BTC-USDT","bids":[["50000","1.5"]],"asks":[["50100","2.0"]]}"#;
981 let mut bytes = json.as_bytes().to_vec();
982
983 let value = ExchangeJsonZeroCopy::parse_orderbook_update::<OwnedValue>(&mut bytes).unwrap();
984 assert!(value.get("symbol").is_some());
985 assert!(value.get("bids").is_some());
986 assert!(value.get("asks").is_some());
987 }
988
989 #[test]
990 fn test_zero_copy_collections() {
991 let data = [1, 2, 3, 4, 5];
992 let small_vec = ZeroCopyCollections::slice_to_small_vec::<i32, 8>(&data);
993 assert_eq!(small_vec.len(), 5);
994 assert_eq!(small_vec[0], 1);
995 assert_eq!(small_vec[4], 5);
996 }
997
998 #[test]
999 fn test_backward_compatibility() {
1000 with_buffer_manager(|manager| {
1002 let stats = manager.get_stats();
1003 assert!(stats.text_buffer_capacity > 0);
1004 });
1005
1006 with_json_buffer_manager(|manager| {
1007 let stats = manager.get_stats();
1008 assert!(stats.json_parse_buffer_capacity > 0);
1009 });
1010 }
1011}