# proto: cannot parse invalid wire-format data

- **ID:** `go/proto-marshal-invalid-wire-type`
- **Domain:** go
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The bytes being unmarshaled are not valid protobuf wire format — typically caused by sending JSON, gzip-compressed payloads, or a message of a different schema over the wire.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   if err := proto.Unmarshal(data, msg); err != nil {
    log.Printf("unmarshal failed: %v, first bytes: % x", err, data[:min(32, len(data))])
    return err
}
   ```
2. **** (86% success)
   ```
   // client
conn, _ := grpc.NewClient(addr,
    grpc.WithDefaultCallOptions(grpc.ForceCodec(proto.Marshaler{})),
)
// server: verify incoming Content-Type header
md, _ := metadata.FromIncomingContext(ctx)
log.Printf("content-type: %v", md["content-type"])
   ```

## Dead Ends

- **** — Unmarshal is deterministic; invalid wire bytes always fail at the same offset. (99% fail)
- **** — Doesn't fix the underlying wire corruption; just moves the failure deeper. (85% fail)
