# Bitchat Android MessageType Enum: The 8 Network Packet Types Explained

> Explore the 8 network packet types in Bitchat Android MessageType enum. Understand every transmission across its decentralized mesh network.

- Repository: [permissionlesstech/bitchat-android](https://github.com/permissionlesstech/bitchat-android)
- Tags: api-reference
- Published: 2026-07-28

---

**The `MessageType` enum in the `permissionlesstech/bitchat-android` codebase defines eight single-byte packet categories that govern every transmission across its decentralized mesh network.**

The Bitchat Android messaging protocol, as implemented in `permissionlesstech/bitchat-android`, relies on a compact binary format to route data efficiently over Bluetooth and local mesh connections. At the heart of this protocol sits the `MessageType` enum declared in [`BinaryProtocol.kt`](https://github.com/permissionlesstech/bitchat-android/blob/main/BinaryProtocol.kt), which assigns a unique `UByte` identifier to every packet so receivers can instantly determine how to process the payload.

## All Message Types in the Bitchat Android MessageType Enum

The `MessageType` enum is declared at lines 12–20 of [`app/src/main/java/com/bitchat/android/protocol/BinaryProtocol.kt`](https://github.com/permissionlesstech/bitchat-android/blob/main/app/src/main/java/com/bitchat/android/protocol/BinaryProtocol.kt). Each constant maps to a hexadecimal value that fits into a single unsigned byte, keeping packet headers minimal.

```kotlin
enum class MessageType(val value: UByte) {
    ANNOUNCE(0x01u),              // Advertises a peer's presence
    MESSAGE(0x02u),               // All user messages (private and broadcast)
    LEAVE(0x03u),                 // Signals peer departure
    NOISE_HANDSHAKE(0x10u),       // Initiates Noise Protocol handshake
    NOISE_ENCRYPTED(0x11u),       // Noise encrypted transport message
    FRAGMENT(0x20u),              // Fragmentation for large packets
    REQUEST_SYNC(0x21u),          // GCS-based sync request
    FILE_TRANSFER(0x22u);         // File transfer packet (BLE voice notes, etc.)
}

```

These eight constants fall into four functional groups.

### Presence and Session Management

- **ANNOUNCE (`0x01u`)** — Advertises a peer's presence when it joins the mesh network.
- **LEAVE (`0x03u`)** — Signals that a peer is gracefully departing the mesh.

### User Messaging and Media

- **MESSAGE (`0x02u`)** — Carries ordinary user content, including both private one-to-one and broadcast messages.
- **FILE_TRANSFER (`0x22u`)** — Handles binary file-transfers such as BLE-based voice notes or other media payloads.

### Encryption and Security

- **NOISE_HANDSHAKE (`0x10u`)** — Kicks off a Noise Protocol handshake to negotiate encrypted sessions between peers.
- **NOISE_ENCRYPTED (`0x11u`)** — Wraps data that has been encrypted using the established Noise session keys.

### Protocol Utilities

- **FRAGMENT (`0x20u`)** — Splits oversized payloads into smaller fragments for reliable reassembly.
- **REQUEST_SYNC (`0x21u`)** — Requests state synchronization backed by Google Cloud Sync (GCS).

## How the Bitchat Android MessageType Enum Is Used in Packet Creation

When building outbound traffic, the application constructs a `BitchatPacket` and sets its `type` field to the corresponding `MessageType.value`. For example, a standard chat packet is assembled as shown in [`BitchatPacket.kt`](https://github.com/permissionlesstech/bitchat-android/blob/main/BitchatPacket.kt):

```kotlin
val packet = BitchatPacket(
    type = MessageType.MESSAGE.value,
    ttl = 5u,
    senderID = myPeerId,
    payload = chatMessageBytes
)

```

To dispatch a file-transfer packet, simply swap the type constant:

```kotlin
val filePacket = BitchatPacket(
    type = MessageType.FILE_TRANSFER.value,
    ttl = 5u,
    senderID = myPeerId,
    payload = fileDataBytes
)

```

## Routing Incoming Packets by MessageType in Bitchat Android

On the receiving side, [`MessageHandler.kt`](https://github.com/permissionlesstech/bitchat-android/blob/main/MessageHandler.kt) acts as the central dispatcher. The pipeline converts the raw `UByte` back into a typed enum constant, then branches on it. Below is the authoritative lookup pattern implemented in the mesh layer:

```kotlin
val incomingType = MessageType.fromValue(receivedPacket.type)
when (incomingType) {
    MessageType.ANNOUNCE      -> handleAnnounce(receivedPacket)
    MessageType.MESSAGE       -> handleMessage(receivedPacket)
    MessageType.LEAVE         -> handleLeave(receivedPacket)
    MessageType.NOISE_HANDSHAKE -> startHandshake(receivedPacket)
    MessageType.NOISE_ENCRYPTED -> processEncrypted(receivedPacket)
    MessageType.FRAGMENT      -> reassembleFragment(receivedPacket)
    MessageType.REQUEST_SYNC  -> requestSync(receivedPacket)
    MessageType.FILE_TRANSFER -> handleFileTransfer(receivedPacket)
    null -> Log.w("Mesh", "Unknown packet type: ${receivedPacket.type}")
}

```

This `when` expression ensures that every inbound byte in the binary protocol is handled deterministically.

## Related Source Files for the Bitchat Android MessageType Enum

Several modules consume or validate the `MessageType` enum:

- **[`app/src/main/java/com/bitchat/android/protocol/BinaryProtocol.kt`](https://github.com/permissionlesstech/bitchat-android/blob/main/app/src/main/java/com/bitchat/android/protocol/BinaryProtocol.kt)** — Defines the enum and the low-level binary packet encoding and decoding logic.
- **[`app/src/main/java/com/bitchat/android/protocol/BitchatPacket.kt`](https://github.com/permissionlesstech/bitchat-android/blob/main/app/src/main/java/com/bitchat/android/protocol/BitchatPacket.kt)** — Data class whose `type` property accepts the `UByte` value drawn from `MessageType`.
- **[`app/src/main/java/com/bitchat/android/mesh/MessageHandler.kt`](https://github.com/permissionlesstech/bitchat-android/blob/main/app/src/main/java/com/bitchat/android/mesh/MessageHandler.kt)** — Interprets incoming `MessageType` values and delegates them to the appropriate handler functions.
- **[`app/src/main/java/com/bitchat/android/mesh/PacketProcessorAnnounceSideEffectTest.kt`](https://github.com/permissionlesstech/bitchat-android/blob/main/app/src/main/java/com/bitchat/android/mesh/PacketProcessorAnnounceSideEffectTest.kt)** — Unit tests that verify correct routing and side-effect behavior for each `MessageType`.

## Summary

- The Bitchat Android `MessageType` enum lives in [`BinaryProtocol.kt`](https://github.com/permissionlesstech/bitchat-android/blob/main/BinaryProtocol.kt) and assigns a single-byte ID to every packet.
- **Eight constants** are defined: `ANNOUNCE`, `MESSAGE`, `LEAVE`, `NOISE_HANDSHAKE`, `NOISE_ENCRYPTED`, `FRAGMENT`, `REQUEST_SYNC`, and `FILE_TRANSFER`.
- These values enable the mesh layer to distinguish presence announcements, encrypted handshakes, chat messages, file transfers, and protocol utilities without parsing the full payload.
- Build packets by passing `MessageType.<CONSTANT>.value` into `BitchatPacket`, and route inbound traffic by converting the raw byte back with `MessageType.fromValue()`.

## Frequently Asked Questions

### What is the MessageType enum used for in Bitchat Android?

The `MessageType` enum is the core packet-type registry for the Bitchat Android mesh protocol. It tells the receiver whether an incoming byte array is a presence announcement, an encrypted message, a file fragment, or another protocol primitive, allowing the app to process the payload efficiently.

### How many message types does Bitchat Android support?

As of the current source tree in `permissionlesstech/bitchat-android`, the protocol supports **eight distinct message types**. They are `ANNOUNCE`, `MESSAGE`, `LEAVE`, `NOISE_HANDSHAKE`, `NOISE_ENCRYPTED`, `FRAGMENT`, `REQUEST_SYNC`, and `FILE_TRANSFER`.

### Where is the MessageType enum defined in the Bitchat Android source code?

The enum is defined at lines 12–20 of **[`app/src/main/java/com/bitchat/android/protocol/BinaryProtocol.kt`](https://github.com/permissionlesstech/bitchat-android/blob/main/app/src/main/java/com/bitchat/android/protocol/BinaryProtocol.kt)**. This same file also houses the binary serialization logic that writes the enum's `UByte` value into packet headers.

### How do I create a packet with a specific MessageType in Kotlin?

Instantiate a `BitchatPacket` and assign `type = MessageType.<CONSTANT>.value`. For example, `MessageType.MESSAGE.value` creates a text message packet, while `MessageType.FILE_TRANSFER.value` creates a media-transfer packet, as implemented in the mesh communication layer of the repository.