@@ -474,3 +474,82 @@ def validate_server_message(msg: ServerMessage) -> bool:
474474 return False
475475
476476 return True
477+
478+
479+ # ============================================================================
480+ # Binary Transfer Message Types (New Feature)
481+ # ============================================================================
482+
483+
484+ class BinaryMetadata (BaseModel ):
485+ """
486+ Metadata for binary data transfer.
487+
488+ This metadata is sent as a text frame before the actual binary data,
489+ allowing receivers to prepare for and validate incoming binary transfers.
490+ """
491+
492+ type : Literal ["binary_data" ] = "binary_data"
493+ filename : Optional [str ] = None
494+ mime_type : Optional [str ] = None
495+ size : int = Field (..., description = "Size of binary data in bytes" )
496+ checksum : Optional [str ] = Field (
497+ None , description = "MD5 or SHA256 checksum for validation"
498+ )
499+ session_id : Optional [str ] = None
500+ description : Optional [str ] = None
501+ timestamp : Optional [str ] = None
502+ # Allow additional custom fields
503+ model_config = ConfigDict (extra = "allow" )
504+
505+
506+ class FileTransferStart (BaseModel ):
507+ """
508+ Message to initiate a chunked file transfer.
509+
510+ Sent before sending file chunks to inform the receiver about
511+ the file details and transfer parameters.
512+ """
513+
514+ type : Literal ["file_transfer_start" ] = "file_transfer_start"
515+ filename : str = Field (..., description = "Name of file being transferred" )
516+ size : int = Field (..., description = "Total file size in bytes" )
517+ chunk_size : int = Field (..., description = "Size of each chunk in bytes" )
518+ total_chunks : int = Field (..., description = "Total number of chunks" )
519+ mime_type : Optional [str ] = Field (None , description = "MIME type of file" )
520+ session_id : Optional [str ] = None
521+ description : Optional [str ] = None
522+ # Allow additional custom fields
523+ model_config = ConfigDict (extra = "allow" )
524+
525+
526+ class FileTransferComplete (BaseModel ):
527+ """
528+ Message to signal completion of a chunked file transfer.
529+
530+ Sent after all file chunks have been transmitted, includes
531+ checksum for validation.
532+ """
533+
534+ type : Literal ["file_transfer_complete" ] = "file_transfer_complete"
535+ filename : str = Field (..., description = "Name of transferred file" )
536+ total_chunks : int = Field (..., description = "Total chunks sent" )
537+ checksum : Optional [str ] = Field (None , description = "MD5 checksum of complete file" )
538+ session_id : Optional [str ] = None
539+ # Allow additional custom fields
540+ model_config = ConfigDict (extra = "allow" )
541+
542+
543+ class ChunkMetadata (BaseModel ):
544+ """
545+ Metadata for a single file chunk.
546+
547+ Sent with each chunk during chunked file transfer to track
548+ chunk sequence and validate chunk integrity.
549+ """
550+
551+ chunk_num : int = Field (..., description = "Chunk sequence number (0-indexed)" )
552+ chunk_size : int = Field (..., description = "Size of this chunk in bytes" )
553+ checksum : Optional [str ] = Field (None , description = "Checksum of this chunk" )
554+ # Allow additional custom fields
555+ model_config = ConfigDict (extra = "allow" )
0 commit comments