MessagePack 示例

MessagePack 二进制序列化格式示例,包含数据结构和使用模式

📝 基本数据结构

🟢 simple

MessagePack 基本数据类型和结构示例

// MessagePack Basic Data Structures Example
// This file contains examples of basic MessagePack data structures
// Note: This shows the conceptual structure, not the actual binary encoding

// Basic Types
{
  "null": null,
  "boolean_true": true,
  "boolean_false": false,
  "integer_pos": 42,
  "integer_neg": -17,
  "integer_big": 2147483647,
  "float_num": 3.14159,
  "string": "Hello, MessagePack!",
  "binary_data": "base64:AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8g"
}

// Array Examples
{
  "empty_array": [],
  "number_array": [1, 2, 3, 4, 5],
  "mixed_array": [42, "hello", true, null, 3.14],
  "nested_array": [[1, 2], [3, 4], [5, 6]]
}

// Map (Object) Examples
{
  "empty_object": {},
  "simple_object": {
    "name": "John Doe",
    "age": 30,
    "email": "[email protected]"
  },
  "nested_object": {
    "user": {
      "id": 123,
      "profile": {
        "name": "Jane Smith",
        "preferences": {
          "theme": "dark",
          "language": "en"
        }
      }
    }
  }
}

// Mixed Structure Examples
{
  "user_list": [
    {
      "id": 1,
      "name": "Alice",
      "active": true
    },
    {
      "id": 2,
      "name": "Bob",
      "active": false
    }
  ],
  "metadata": {
    "total": 2,
    "page": 1,
    "limit": 10
  }
}

// Timestamp Example
{
  "created_at": 1705123456, // Unix timestamp
  "updated_at": "2024-01-13T10:24:16Z" // ISO string format
}

// Binary Data Example
{
  "image_data": "base64:/9j/4AAQSkZJRgABAQAAAQ...",
  "file_hash": "sha256:a1b2c3d4e5f6...",
  "encryption_key": "base64:SGVsbG9Xb3JsZA=="
}

// Extended Types Example
{
  "custom_timestamp": {
    "__type": "timestamp",
    "value": 1705123456,
    "format": "unix"
  },
  "custom_uuid": {
    "__type": "uuid",
    "value": "550e8400-e29b-41d4-a716-446655440000"
  },
  "custom_decimal": {
    "__type": "decimal",
    "value": "123.45",
    "precision": 2
  }
}

📝 用户档案数据

🟡 intermediate

用户信息的 MessagePack 序列化示例

// User Profile MessagePack Structure
// Optimized for storage and transmission efficiency

{
  "user": {
    "id": 12345,
    "username": "johndoe",
    "email": "[email protected]",
    "profile": {
      "first_name": "John",
      "last_name": "Doe",
      "display_name": "John Doe",
      "avatar_url": "https://cdn.example.com/avatars/user_12345.jpg",
      "bio": "Software developer passionate about creating amazing applications.",
      "location": "San Francisco, CA",
      "website": "https://johndoe.dev",
      "company": "Tech Corp",
      "job_title": "Senior Software Engineer"
    },
    "demographics": {
      "date_of_birth": "1990-05-15",
      "gender": "male",
      "language": "en",
      "timezone": "America/Los_Angeles",
      "country": "US"
    },
    "preferences": {
      "theme": "dark",
      "language": "en",
      "timezone": "America/Los_Angeles",
      "notifications": {
        "email": true,
        "push": true,
        "sms": false,
        "marketing": false,
        "security": true,
        "updates": true
      },
      "privacy": {
        "profile_visibility": "public",
        "show_email": false,
        "show_phone": false,
        "allow_friend_requests": true,
        "search_indexing": false
      },
      "display": {
        "font_size": 14,
        "font_family": "Inter",
        "compact_mode": false,
        "show_tooltips": true,
        "auto_play_videos": false
      }
    },
    "activity": {
      "last_login": 1705123456,
      "login_count": 152,
      "last_seen": 1705123400,
      "online_status": "online",
      "is_typing": false,
      "away_status": "available"
    },
    "connections": {
      "followers_count": 1250,
      "following_count": 423,
      "friends_count": 89,
      "mutual_connections": [
        23456, 34567, 45678, 56789, 67890
      ]
    },
    "subscription": {
      "plan": "premium",
      "status": "active",
      "started_at": 1640995200,
      "expires_at": 1704067200,
      "auto_renew": true,
      "features": [
        "unlimited_storage",
        "advanced_analytics",
        "priority_support",
        "api_access"
      ]
    },
    "security": {
      "two_factor_enabled": true,
      "two_factor_method": "totp",
      "last_password_change": 1698710400,
      "failed_login_attempts": 0,
      "account_locked": false,
      "trusted_devices": [
        {
          "device_id": "device_abc123",
          "name": "iPhone 13",
          "last_used": 1705123456,
          "trusted": true
        }
      ]
    },
    "metadata": {
      "created_at": 1609459200,
      "updated_at": 1705123456,
      "version": 2,
      "source": "web_app",
      "ip_address": "192.168.1.100",
      "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
    }
  }
}

// Compact Version for Mobile/Storage
{
  "uid": 12345,
  "un": "johndoe",
  "em": "[email protected]",
  "fn": "John",
  "ln": "Doe",
  "av": "https://cdn.example.com/avatars/user_12345.jpg",
  "stat": "online",
  "ll": 1705123456,
  "fc": 1250,
  "pl": "premium",
  "tf": true,
  "tz": "America/Los_Angeles",
  "th": "dark",
  "nt": {
    "e": true,
    "p": true,
    "s": false
  }
}

📝 IoT传感器数据

🟡 intermediate

物联网设备数据的高效 MessagePack 表示

// IoT Device Data MessagePack Structure
// Optimized for high-frequency, low-bandwidth transmission

{
  "device": {
    "id": "sensor_001",
    "type": "temperature_humidity",
    "location": {
      "room": "server_room",
      "building": "data_center_a",
      "coordinates": {
        "lat": 37.7749,
        "lng": -122.4194,
        "floor": 2,
        "rack": "A-15"
      }
    },
    "firmware": "1.2.3",
    "battery": 85.2,
    "signal_strength": -45,
    "status": "online"
  },
  "timestamp": 1705123456,
  "sensors": [
    {
      "id": "temp_001",
      "type": "temperature",
      "value": 22.5,
      "unit": "celsius",
      "quality": 0.98,
      "calibrated": true
    },
    {
      "id": "hum_001",
      "type": "humidity",
      "value": 45.8,
      "unit": "percent",
      "quality": 0.95,
      "calibrated": true
    },
    {
      "id": "press_001",
      "type": "pressure",
      "value": 1013.25,
      "unit": "hPa",
      "quality": 0.99,
      "calibrated": false
    }
  ],
  "metrics": {
    "cpu_usage": 12.5,
    "memory_usage": 67.8,
    "storage_usage": 45.2,
    "network_tx": 1024.5,
    "network_rx": 2048.7,
    "uptime": 86400
  },
  "events": [
    {
      "type": "threshold_warning",
      "sensor_id": "temp_001",
      "message": "Temperature approaching upper limit",
      "severity": "warning",
      "timestamp": 1705123400
    }
  ],
  "alerts": [],
  "health": {
    "overall": "good",
    "last_maintenance": 1704067200,
    "next_maintenance": 1706659200,
    "self_test": {
      "last_run": 1705123200,
      "status": "passed",
      "checks": {
        "sensor_calibration": "ok",
        "battery_check": "ok",
        "connectivity": "ok",
        "memory_test": "ok"
      }
    }
  }
}

// Batch Data Transmission Format
{
  "batch": {
    "device_id": "sensor_001",
    "batch_id": "batch_20240113_001",
    "start_time": 1705123200,
    "end_time": 1705123400,
    "interval": 60,
    "readings": [
      {
        "timestamp": 1705123200,
        "temp": 22.1,
        "hum": 45.2,
        "press": 1013.1
      },
      {
        "timestamp": 1705123260,
        "temp": 22.3,
        "hum": 45.5,
        "press": 1013.2
      },
      {
        "timestamp": 1705123320,
        "temp": 22.5,
        "hum": 45.8,
        "press": 1013.25
      },
      {
        "timestamp": 1705123380,
        "temp": 22.7,
        "hum": 46.1,
        "press": 1013.3
      }
    ],
    "statistics": {
      "temperature": {
        "min": 22.1,
        "max": 22.7,
        "avg": 22.4,
        "std": 0.2
      },
      "humidity": {
        "min": 45.2,
        "max": 46.1,
        "avg": 45.7,
        "std": 0.3
      }
    },
    "events": [],
    "quality": 0.97
  }
}

// Compact Telemetry Format (for high-frequency transmission)
{
  "id": "sensor_001",
  "ts": 1705123456,
  "t": 22.5,
  "h": 45.8,
  "p": 1013.25,
  "b": 85.2,
  "s": -45,
  "q": 0.98
}

// Device Registration Message
{
  "action": "register",
  "device": {
    "id": "sensor_001",
    "type": "temperature_humidity",
    "manufacturer": "SensorTech",
    "model": "TH-2000",
    "firmware": "1.2.3",
    "capabilities": [
      "temperature",
      "humidity",
      "pressure",
      "battery_monitoring",
      "over_the_air_update"
    ],
    "location": {
      "building": "data_center_a",
      "floor": 2,
      "coordinates": {
        "lat": 37.7749,
        "lng": -122.4194
      }
    },
    "configuration": {
      "sampling_rate": 60,
      "transmission_interval": 300,
      "thresholds": {
        "temp_min": 18.0,
        "temp_max": 28.0,
        "hum_min": 30.0,
        "hum_max": 70.0
      }
    }
  },
  "auth": {
    "api_key": "sensor_api_key_12345",
    "certificate": "base64:MIIDdzCCAl+gAwIBAgIEbG...",
    "signature": "base64:ABC123DEF456..."
  }
}

📝 API响应数据

🟡 intermediate

Web API 响应的 MessagePack 优化格式

// Web API Response MessagePack Structure
// Optimized for reduced bandwidth and faster parsing

{
  "response": {
    "success": true,
    "status_code": 200,
    "message": "Request completed successfully",
    "timestamp": 1705123456,
    "request_id": "req_123456789",
    "version": "1.0.0",
    "server": "api-server-03"
  },
  "data": {
    "users": [
      {
        "id": 12345,
        "username": "johndoe",
        "email": "[email protected]",
        "first_name": "John",
        "last_name": "Doe",
        "avatar": "https://cdn.example.com/avatars/12345.jpg",
        "status": "active",
        "created_at": "2024-01-10T10:30:00Z",
        "last_login": "2024-01-13T09:15:00Z",
        "roles": ["user", "premium"],
        "preferences": {
          "theme": "dark",
          "language": "en",
          "timezone": "America/Los_Angeles"
        }
      },
      {
        "id": 67890,
        "username": "janesmith",
        "email": "[email protected]",
        "first_name": "Jane",
        "last_name": "Smith",
        "avatar": "https://cdn.example.com/avatars/67890.jpg",
        "status": "active",
        "created_at": "2024-01-08T14:20:00Z",
        "last_login": "2024-01-13T11:45:00Z",
        "roles": ["user"],
        "preferences": {
          "theme": "light",
          "language": "en",
          "timezone": "America/New_York"
        }
      }
    ],
    "pagination": {
      "page": 1,
      "per_page": 20,
      "total": 1250,
      "total_pages": 63,
      "has_next": true,
      "has_prev": false
    },
    "filters_applied": {
      "status": "active",
      "roles": ["user"],
      "search": null,
      "sort_by": "created_at",
      "sort_order": "desc"
    }
  },
  "metadata": {
    "execution_time_ms": 45,
    "cache_hit": false,
    "server_id": "api-server-03",
    "region": "us-west-2",
    "rate_limit": {
      "remaining": 995,
      "limit": 1000,
      "reset_at": 1705127056
    }
  }
}

// Compact API Response Format
{
  "s": true,
  "c": 200,
  "t": 1705123456,
  "d": [
    [12345, "johndoe", "[email protected]", "John", "Doe",
     "https://cdn.example.com/avatars/12345.jpg", "active",
     "2024-01-10T10:30:00Z", ["user", "premium"]],
    [67890, "janesmith", "[email protected]", "Jane", "Smith",
     "https://cdn.example.com/avatars/67890.jpg", "active",
     "2024-01-08T14:20:00Z", ["user"]]
  ],
  "p": {"page": 1, "per": 20, "total": 1250, "pages": 63, "next": true, "prev": false},
  "meta": {"time": 45, "cache": false, "rl": {"rem": 995, "lim": 1000}}
}

// Error Response Format
{
  "response": {
    "success": false,
    "status_code": 400,
    "message": "Validation failed",
    "timestamp": 1705123456,
    "request_id": "req_123456789"
  },
  "error": {
    "code": "VALIDATION_ERROR",
    "type": "validation",
    "message": "Request data validation failed",
    "details": [
      {
        "field": "email",
        "code": "INVALID_FORMAT",
        "message": "Email format is invalid",
        "value": "invalid-email"
      },
      {
        "field": "password",
        "code": "TOO_SHORT",
        "message": "Password must be at least 8 characters long",
        "value": "abc123"
      }
    ],
    "suggestions": [
      "Please provide a valid email address",
      "Password should contain at least 8 characters with mixed case and numbers"
    ]
  },
  "metadata": {
    "execution_time_ms": 12,
    "server_id": "api-server-01",
    "region": "us-west-2"
  }
}

// Paginated List Response with Embedded Resources
{
  "response": {
    "success": true,
    "status_code": 200,
    "timestamp": 1705123456
  },
  "data": {
    "items": [
      {
        "id": "post_123",
        "title": "Getting Started with MessagePack",
        "content": "MessagePack is a binary serialization format...",
        "author_id": 12345,
        "author": {
          "username": "johndoe",
          "display_name": "John Doe",
          "avatar": "https://cdn.example.com/avatars/12345.jpg"
        },
        "category": {
          "id": "cat_tech",
          "name": "Technology",
          "slug": "technology"
        },
        "tags": ["messagepack", "serialization", "performance"],
        "stats": {
          "views": 1520,
          "likes": 89,
          "comments": 12,
          "shares": 5
        },
        "created_at": "2024-01-10T10:30:00Z",
        "updated_at": "2024-01-13T09:15:00Z",
        "published": true
      }
    ],
    "pagination": {
      "page": 1,
      "per_page": 10,
      "total": 156,
      "total_pages": 16
    },
    "includes": {
      "authors": {
        "12345": {
          "username": "johndoe",
          "display_name": "John Doe",
          "avatar": "https://cdn.example.com/avatars/12345.jpg",
          "verified": true,
          "followers": 1250
        }
      },
      "categories": {
        "cat_tech": {
          "name": "Technology",
          "slug": "technology",
          "description": "Technology related articles",
          "post_count": 892
        }
      }
    }
  }
}

// Real-time Data Stream Response
{
  "stream": {
    "type": "real_time_updates",
    "channel": "user_notifications",
    "timestamp": 1705123456,
    "sequence": 12345
  },
  "events": [
    {
      "id": "event_001",
      "type": "notification",
      "data": {
        "user_id": 12345,
        "title": "New message received",
        "body": "You have a new message from Jane Smith",
        "icon": "message",
        "priority": "normal",
        "actions": [
          {"id": "view", "label": "View Message"},
          {"id": "dismiss", "label": "Dismiss"}
        ],
        "metadata": {
          "sender_id": 67890,
          "conversation_id": "conv_123"
        }
      },
      "timestamp": 1705123456001
    },
    {
      "id": "event_002",
      "type": "status_update",
      "data": {
        "user_id": 12345,
        "status": "online",
        "last_seen": 1705123456
      },
      "timestamp": 1705123456002
    }
  ]
}

// Bulk Operations Response
{
  "response": {
    "success": true,
    "status_code": 207,
    "message": "Bulk operation completed",
    "timestamp": 1705123456
  },
  "results": [
    {
      "index": 0,
      "id": "item_001",
      "success": true,
      "status_code": 201,
      "message": "Item created successfully"
    },
    {
      "index": 1,
      "id": "item_002",
      "success": false,
      "status_code": 400,
      "message": "Validation failed",
      "errors": [
        {
          "field": "name",
          "code": "REQUIRED",
          "message": "Name is required"
        }
      ]
    },
    {
      "index": 2,
      "id": "item_003",
      "success": true,
      "status_code": 200,
      "message": "Item updated successfully"
    }
  ],
  "summary": {
    "total": 3,
    "successful": 2,
    "failed": 1,
    "created": 1,
    "updated": 1,
    "errors": 1
  }
}

📝 游戏状态数据

🔴 complex

实时游戏状态的 MessagePack 序列化

// Real-time Game State MessagePack Structure
// Optimized for low-latency multiplayer games

{
  "game_state": {
    "session_id": "game_session_12345",
    "timestamp": 1705123456,
    "tick": 15420,
    "map_id": "map_battle_royale_01",
    "game_mode": "battle_royale",
    "max_players": 100,
    "current_players": 87,
    "status": "in_progress",
    "time_remaining": 1200,
    "safe_zone": {
      "center": {"x": 5000.5, "y": 3000.25},
      "radius": 850.75,
      "next_center": {"x": 5200.0, "y": 3200.0},
      "next_radius": 650.5,
      "shrink_start": 1705123650
    }
  },
  "players": [
    {
      "id": "player_001",
      "username": "ProGamer123",
      "team": "alpha",
      "position": {"x": 5123.45, "y": 3456.78, "z": 125.5},
      "rotation": {"pitch": 15.5, "yaw": 89.25, "roll": 0.0},
      "velocity": {"x": 5.2, "y": 0.0, "z": 2.1},
      "health": 95,
      "armor": 50,
      "shields": 75,
      "stats": {
        "kills": 3,
        "deaths": 0,
        "assists": 1,
        "damage_dealt": 285,
        "damage_taken": 45
      },
      "weapons": [
        {
          "id": "weapon_rifle_001",
          "type": "assault_rifle",
          "ammo_current": 25,
          "ammo_reserve": 180,
          "fire_mode": "single",
          "attachments": ["scope_4x", "silencer"]
        },
        {
          "id": "weapon_pistol_001",
          "type": "pistol",
          "ammo_current": 12,
          "ammo_reserve": 24,
          "fire_mode": "single",
          "attachments": []
        }
      ],
      "items": [
        {
          "id": "item_health_001",
          "type": "medkit",
          "quantity": 2,
          "quality": "rare"
        },
        {
          "id": "item_armor_001",
          "type": "body_armor",
          "quantity": 1,
          "quality": "epic"
        }
      ],
      "status": {
        "alive": true,
        "downed": false,
        "reviving": false,
        "sprinting": false,
        "crouching": true,
        "aiming": false,
        "reloading": false
      },
      "effects": [
        {
          "type": "speed_boost",
          "duration": 30,
          "intensity": 1.25
        }
      ]
    }
  ],
  "entities": [
    {
      "id": "entity_001",
      "type": "weapon_crate",
      "position": {"x": 5200.0, "y": 3500.0, "z": 0.0},
      "rotation": 0,
      "contents": {
        "weapon_type": "sniper_rifle",
        "ammo_count": 10,
        "attachments": ["scope_8x"]
      },
      "state": "unopened"
    },
    {
      "id": "entity_002",
      "type": "vehicle",
      "position": {"x": 5100.0, "y": 3300.0, "z": 0.0},
      "rotation": 45.5,
      "health": 80,
      "fuel": 65.5,
      "occupants": ["player_002"],
      "state": "drivable"
    }
  ],
  "projectiles": [
    {
      "id": "proj_001",
      "type": "bullet",
      "owner_id": "player_001",
      "position": {"x": 5150.0, "y": 3400.0, "z": 120.0},
      "velocity": {"x": 850.0, "y": 0.0, "z": -5.0},
      "damage": 25,
      "lifetime": 0.15
    }
  ],
  "environment": {
    "weather": "clear",
    "time_of_day": "day",
    "visibility": 1000.0,
    "wind": {
      "direction": 225,
      "speed": 5.5
    },
    "audio_events": [
      {
        "type": "explosion",
        "position": {"x": 5300.0, "y": 3600.0, "z": 0.0},
        "intensity": 0.8,
        "radius": 200.0
      }
    ]
  },
  "events": [
    {
      "type": "player_killed",
      "timestamp": 1705123450,
      "victim_id": "player_003",
      "killer_id": "player_001",
      "weapon_id": "weapon_rifle_001",
      "position": {"x": 5180.5, "y": 3420.25, "z": 115.0}
    },
    {
      "type": "item_picked_up",
      "timestamp": 1705123452,
      "player_id": "player_001",
      "item_id": "item_ammo_001",
      "quantity": 30
    }
  ]
}

// Compact Update Delta Format (only changed data)
{
  "session_id": "game_session_12345",
  "timestamp": 1705123456,
  "tick": 15420,
  "delta": {
    "players": {
      "player_001": {
        "pos": {"x": 5123.45, "y": 3456.78, "z": 125.5},
        "rot": {"p": 15.5, "y": 89.25, "r": 0.0},
        "vel": {"x": 5.2, "y": 0.0, "z": 2.1},
        "h": 95,
        "a": 50,
        "s": 75,
        "st": {"alive": true, "crouching": true}
      }
    },
    "projectiles": [
      {
        "id": "proj_001",
        "pos": {"x": 5150.0, "y": 3400.0, "z": 120.0},
        "vel": {"x": 850.0, "y": 0.0, "z": -5.0}
      }
    ],
    "events": [
      {
        "type": "player_killed",
        "ts": 1705123450,
        "v": "player_003",
        "k": "player_001",
        "w": "weapon_rifle_001",
        "pos": {"x": 5180.5, "y": 3420.25, "z": 115.0}
      }
    ]
  }
}

// Player State Snapshot (for specific player)
{
  "player_state": {
    "id": "player_001",
    "timestamp": 1705123456,
    "local_position": {"x": 0, "y": 0, "z": 0},
    "health": 95,
    "armor": 50,
    "ammo": {
      "primary": {"current": 25, "reserve": 180},
      "secondary": {"current": 12, "reserve": 24}
    },
    "inventory": [
      {"id": "medkit", "count": 2},
      {"id": "grenade", "count": 1}
    ],
    "minimap": {
      "center": {"x": 5123.45, "y": 3456.78},
      "radius": 150.0,
      "entities": [
        {"type": "enemy", "pos": {"x": 5200.0, "y": 3500.0}},
        {"type": "item", "pos": {"x": 5100.0, "y": 3400.0}}
      ]
    }
  }
}

📝 金融行情数据

🔴 complex

高频金融数据的 MessagePack 优化格式

// High-Frequency Financial Data MessagePack Structure
// Optimized for minimal bandwidth and maximum processing speed

{
  "market_data": {
    "exchange": "NASDAQ",
    "timestamp": 1705123456,
    "session": "regular",
    "timezone": "America/New_York"
  },
  "ticks": [
    {
      "symbol": "AAPL",
      "price": 195.42,
      "volume": 150,
      "bid": 195.40,
      "ask": 195.42,
      "bid_size": 500,
      "ask_size": 300,
      "change": 0.85,
      "change_percent": 0.44,
      "timestamp": 1705123456001,
      "exchange": "NASDAQ",
      "conditions": ["regular"]
    },
    {
      "symbol": "GOOGL",
      "price": 142.78,
      "volume": 85,
      "bid": 142.76,
      "ask": 142.78,
      "bid_size": 200,
      "ask_size": 150,
      "change": -0.32,
      "change_percent": -0.22,
      "timestamp": 1705123456002,
      "exchange": "NASDAQ",
      "conditions": ["regular"]
    },
    {
      "symbol": "MSFT",
      "price": 378.91,
      "volume": 120,
      "bid": 378.89,
      "ask": 378.91,
      "bid_size": 400,
      "ask_size": 250,
      "change": 2.15,
      "change_percent": 0.57,
      "timestamp": 1705123456003,
      "exchange": "NASDAQ",
      "conditions": ["regular"]
    }
  ],
  "market_summary": {
    "indices": [
      {
        "symbol": "SPY",
        "price": 478.25,
        "change": 1.25,
        "change_percent": 0.26
      },
      {
        "symbol": "QQQ",
        "price": 415.67,
        "change": 1.89,
        "change_percent": 0.46
      },
      {
        "symbol": "DIA",
        "price": 378.94,
        "change": 0.45,
        "change_percent": 0.12
      }
    ],
    "volume": {
      "total": 284567890,
      "advancing": 1234,
      "declining": 1567,
      "unchanged": 89
    }
  }
}

// Ultra-Compact Tick Format (for HFT systems)
{
  "t": 1705123456,
  "d": [
    [1, "AAPL", 19542, 150, 19540, 19542, 500, 300, 85, 44, 1],
    [2, "GOOGL", 14278, 85, 14276, 14278, 200, 150, -32, -22, 1],
    [3, "MSFT", 37891, 120, 37889, 37891, 400, 250, 215, 57, 1]
  ]
}

// Order Book Snapshot
{
  "order_book": {
    "symbol": "AAPL",
    "exchange": "NASDAQ",
    "timestamp": 1705123456,
    "sequence": 1234567,
    "bids": [
      [195.42, 500],
      [195.41, 300],
      [195.40, 800],
      [195.39, 200],
      [195.38, 450]
    ],
    "asks": [
      [195.43, 250],
      [195.44, 400],
      [195.45, 600],
      [195.46, 150],
      [195.47, 350]
    ],
    "spread": 0.01,
    "mid_price": 195.425
  }
}

// Trade Data
{
  "trades": [
    {
      "symbol": "AAPL",
      "price": 195.42,
      "size": 150,
      "timestamp": 1705123456001,
      "exchange": "NASDAQ",
      "conditions": ["regular"],
      "trade_id": "trade_123456789"
    },
    {
      "symbol": "AAPL",
      "price": 195.41,
      "size": 200,
      "timestamp": 1705123456002,
      "exchange": "NASDAQ",
      "conditions": ["regular"],
      "trade_id": "trade_123456790"
    }
  ]
}

// Level 2 Market Data (Depth of Market)
{
  "depth": {
    "symbol": "AAPL",
    "exchange": "NASDAQ",
    "timestamp": 1705123456,
    "levels": 10,
    "bids": [
      [195.42, 500, "12345"],
      [195.41, 300, "12346"],
      [195.40, 800, "12347"],
      [195.39, 200, "12348"],
      [195.38, 450, "12349"],
      [195.37, 600, "12350"],
      [195.36, 350, "12351"],
      [195.35, 900, "12352"],
      [195.34, 275, "12353"],
      [195.33, 425, "12354"]
    ],
    "asks": [
      [195.43, 250, "54321"],
      [195.44, 400, "54320"],
      [195.45, 600, "54319"],
      [195.46, 150, "54318"],
      [195.47, 350, "54317"],
      [195.48, 500, "54316"],
      [195.49, 275, "54315"],
      [195.50, 800, "54314"],
      [195.51, 425, "54313"],
      [195.52, 325, "54312"]
    ]
  }
}

// Options Chain Data
{
  "options_chain": {
    "symbol": "AAPL",
    "expiration_date": "2024-01-19",
    "spot_price": 195.42,
    "calls": [
      {
        "strike": 190.0,
        "last": 8.25,
        "bid": 8.20,
        "ask": 8.30,
        "volume": 1250,
        "open_interest": 15420,
        "implied_volatility": 0.28,
        "delta": 0.68,
        "gamma": 0.025,
        "theta": -0.045,
        "vega": 0.18
      },
      {
        "strike": 195.0,
        "last": 5.50,
        "bid": 5.45,
        "ask": 5.55,
        "volume": 2100,
        "open_interest": 18650,
        "implied_volatility": 0.26,
        "delta": 0.52,
        "gamma": 0.032,
        "theta": -0.052,
        "vega": 0.22
      }
    ],
    "puts": [
      {
        "strike": 190.0,
        "last": 2.85,
        "bid": 2.80,
        "ask": 2.90,
        "volume": 980,
        "open_interest": 12450,
        "implied_volatility": 0.25,
        "delta": -0.32,
        "gamma": 0.025,
        "theta": -0.041,
        "vega": 0.18
      },
      {
        "strike": 195.0,
        "last": 4.75,
        "bid": 4.70,
        "ask": 4.80,
        "volume": 1850,
        "open_interest": 15200,
        "implied_volatility": 0.24,
        "delta": -0.48,
        "gamma": 0.032,
        "theta": -0.048,
        "vega": 0.22
      }
    ]
  }
}

// Real-time Analytics Data
{
  "analytics": {
    "timestamp": 1705123456,
    "market": {
      "volatility_index": 16.5,
      "fear_greed_index": 72,
      "market_mood": "bullish",
      "sector_performance": {
        "technology": 1.25,
        "healthcare": 0.85,
        "finance": -0.45,
        "energy": 0.15
      }
    },
    "alerts": [
      {
        "type": "price_alert",
        "symbol": "AAPL",
        "trigger_price": 195.50,
        "current_price": 195.42,
        "direction": "above",
        "timestamp": 1705123450
      },
      {
        "type": "volume_spike",
        "symbol": "MSFT",
        "volume_ratio": 2.3,
        "avg_volume": 85000000,
        "current_volume": 195500000,
        "timestamp": 1705123452
      }
    ]
  }
}