(buffer *bytes.Buffer, maxSize int, compression CompressionType, sp opentracing.Span)
| 231 | } |
| 232 | |
| 233 | func decompressFromBuffer(buffer *bytes.Buffer, maxSize int, compression CompressionType, sp opentracing.Span) ([]byte, error) { |
| 234 | if len(buffer.Bytes()) > maxSize { |
| 235 | return nil, fmt.Errorf(messageSizeLargerErrFmt, len(buffer.Bytes()), maxSize) |
| 236 | } |
| 237 | switch compression { |
| 238 | case NoCompression: |
| 239 | return buffer.Bytes(), nil |
| 240 | case RawSnappy: |
| 241 | if sp != nil { |
| 242 | sp.LogFields(otlog.String("event", "util.ParseProtoRequest[decompress]"), |
| 243 | otlog.Int("size", len(buffer.Bytes()))) |
| 244 | } |
| 245 | size, err := snappy.DecodedLen(buffer.Bytes()) |
| 246 | if err != nil { |
| 247 | return nil, err |
| 248 | } |
| 249 | if size > maxSize { |
| 250 | return nil, fmt.Errorf(messageSizeLargerErrFmt, size, maxSize) |
| 251 | } |
| 252 | body, err := snappy.Decode(nil, buffer.Bytes()) |
| 253 | if err != nil { |
| 254 | return nil, err |
| 255 | } |
| 256 | return body, nil |
| 257 | } |
| 258 | return nil, nil |
| 259 | } |
| 260 | |
| 261 | // tryBufferFromReader attempts to cast the reader to a `*bytes.Buffer` this is possible when using httpgrpc. |
| 262 | // If it fails it will return nil and false. |
no test coverage detected