setCallInfoCodec should only be called after CallOptions have been applied.
(c *callInfo)
| 1158 | |
| 1159 | // setCallInfoCodec should only be called after CallOptions have been applied. |
| 1160 | func setCallInfoCodec(c *callInfo) error { |
| 1161 | if c.codec != nil { |
| 1162 | // codec was already set by a CallOption; use it, but set the content |
| 1163 | // subtype if it is not set. |
| 1164 | if c.contentSubtype == "" { |
| 1165 | // c.codec is a baseCodec to hide the difference between grpc.Codec and |
| 1166 | // encoding.Codec (Name vs. String method name). We only support |
| 1167 | // setting content subtype from encoding.Codec to avoid a behavior |
| 1168 | // change with the deprecated version. |
| 1169 | if ec, ok := c.codec.(encoding.CodecV2); ok { |
| 1170 | c.contentSubtype = strings.ToLower(ec.Name()) |
| 1171 | } |
| 1172 | } |
| 1173 | return nil |
| 1174 | } |
| 1175 | |
| 1176 | if c.contentSubtype == "" { |
| 1177 | // No codec specified in CallOptions; use proto by default. |
| 1178 | c.codec = getCodec(proto.Name) |
| 1179 | return nil |
| 1180 | } |
| 1181 | |
| 1182 | // c.contentSubtype is already lowercased in CallContentSubtype |
| 1183 | c.codec = getCodec(c.contentSubtype) |
| 1184 | if c.codec == nil { |
| 1185 | return status.Errorf(codes.Internal, "no codec registered for content-subtype %s", c.contentSubtype) |
| 1186 | } |
| 1187 | return nil |
| 1188 | } |
| 1189 | |
| 1190 | // The SupportPackageIsVersion variables are referenced from generated protocol |
| 1191 | // buffer files to ensure compatibility with the gRPC version used. The latest |
no test coverage detected