# proto: cannot parse invalid wire-format data

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

## Root Cause

The byte slice passed to proto.Unmarshal is not a valid protobuf encoding for the target message — often because the client and server use different .proto definitions or the payload is not protobuf at all.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| google.golang.org/protobuf v1.28+ | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Verify the sender and receiver share the exact same .proto file. Regenerate stubs and compare descriptor hashes:
import "google.golang.org/protobuf/reflect/protoreflect"
desc := (&pb.MyMsg{}).ProtoReflect().Descriptor()
log.Printf("msg=%s pkg=%s", desc.FullName(), desc.ParentFile().Package())
   ```
2. **** (80% success)
   ```
   Wrap Unmarshal with a length check and hex dump on failure to identify the payload:
if err := proto.Unmarshal(data, msg); err != nil {
  log.Printf("unmarshal failed: %v, first16=%x", err, data[:min(16,len(data))])
  return err
}
   ```

## Dead Ends

- **** — Wire-format mismatch is a schema problem, not a size problem; retrying with more memory won't help. (95% fail)
- **** — If the wire bytes are actually protobuf, JSON parsing fails; if they're JSON, the sender is misconfigured. (85% fail)
