ParseEnvelope decodes, validates, and normalizes one raw envelope.
(data []byte, opts ValidateOptions)
| 69 | |
| 70 | // ParseEnvelope decodes, validates, and normalizes one raw envelope. |
| 71 | func ParseEnvelope(data []byte, opts ValidateOptions) (Envelope, error) { |
| 72 | if err := rejectLegacyEnvelopeFields(data); err != nil { |
| 73 | return Envelope{}, err |
| 74 | } |
| 75 | var env Envelope |
| 76 | if err := json.Unmarshal(data, &env); err != nil { |
| 77 | return Envelope{}, fmt.Errorf("%w: decode envelope: %w", ErrInvalidEnvelope, err) |
| 78 | } |
| 79 | return NormalizeEnvelope(env, opts) |
| 80 | } |
| 81 | |
| 82 | // NormalizeEnvelope trims identifier fields, validates the envelope, and |
| 83 | // returns a safe cloned copy for downstream use. |