# proto: cannot parse invalid wire-format data

- **ID:** `go/protobuf-unmarshal-invalid-wire`
- **Domain:** go
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The bytes passed to proto.Unmarshal do not conform to protobuf wire format — often because the data is JSON, empty, truncated, or a different proto message type entirely.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| google.golang.org/protobuf 1.x | active | — | — |

## Workarounds

1. **** (85% success)
   ```
   var msg pb.User
if json.Valid(data) {
  err = protojson.Unmarshal(data, &msg)
} else {
  err = proto.Unmarshal(data, &msg)
}
if err != nil { return fmt.Errorf("decode: %w", err) }
   ```
2. **** (80% success)
   ```
   if len(data) > 0 {
  log.Printf("first bytes: %x", data[:min(len(data),16)])
}
// JSON starts with '{' = 0x7b; protobuf field tag usually 0x0a etc.
   ```

## Dead Ends

- **** — Wire format is deterministic; identical bytes yield identical failure. (95% fail)
- **** — If bytes are binary protobuf, JSON parser fails; if JSON, the original was wrong type. (70% fail)
