(buffer *bytes.Buffer, maxSize int, compression CompressionType, sp trace.Span)
| 209 | } |
| 210 | |
| 211 | func decompressFromBuffer(buffer *bytes.Buffer, maxSize int, compression CompressionType, sp trace.Span) ([]byte, error) { |
| 212 | if len(buffer.Bytes()) > maxSize { |
| 213 | return nil, fmt.Errorf(messageSizeLargerErrFmt, len(buffer.Bytes()), maxSize) |
| 214 | } |
| 215 | switch compression { |
| 216 | case NoCompression: |
| 217 | return buffer.Bytes(), nil |
| 218 | case RawSnappy: |
| 219 | if sp != nil { |
| 220 | sp.SetAttributes(attribute.String("event", "util.ParseProtoRequest[decompress]"), |
| 221 | attribute.Int("size", len(buffer.Bytes()))) |
| 222 | } |
| 223 | size, err := snappy.DecodedLen(buffer.Bytes()) |
| 224 | if err != nil { |
| 225 | return nil, err |
| 226 | } |
| 227 | if size > maxSize { |
| 228 | return nil, fmt.Errorf(messageSizeLargerErrFmt, size, maxSize) |
| 229 | } |
| 230 | body, err := snappy.Decode(nil, buffer.Bytes()) |
| 231 | if err != nil { |
| 232 | return nil, err |
| 233 | } |
| 234 | return body, nil |
| 235 | } |
| 236 | return nil, nil |
| 237 | } |
| 238 | |
| 239 | // tryBufferFromReader attempts to cast the reader to a `*bytes.Buffer` this is possible when using httpgrpc. |
| 240 | // If it fails it will return nil and false. |
no test coverage detected