alibaba / hessian2-codec

hessian2-codec it is a complete C++ implementation of hessian2 spec
Apache License 2.0
26 stars 9 forks source link

support setting the initial offset #13

Closed wbpcode closed 3 years ago

wbpcode commented 3 years ago

I'm not sure I have the right idea. But I think there does need to be a way to set the initial offset of the reader. This would allow us to skip parsing some content if necessary.

Signed-off-by: wbpcode comems@msn.com

zyfjeff commented 3 years ago

Envoy integrating Hessian2-codec requires you to implement your own custom readers and writers to match the Buffer interface inside the Envoy.

class BufferReader : public hessian2::Reader {
public:
  BufferReader(Buffer::Instance& buffer) : buffer_(buffer) {}
  virtual ~BufferReader() override = default;
  virtual void RawReadNbytes(void* out, size_t len, size_t peek_offset) override {
    ASSERT(ByteAvailable() + peek_offset >= len);
    buffer_.copyOut(Offset() + peek_offset, len, out);
  }
  virtual uint64_t Length() const override { return buffer_.length(); }

private:
  const Buffer::Instance& buffer_;
};

@wbpcode

wbpcode commented 3 years ago

@zyfjeff Yes, you are right. It's protected not private.

wbpcode commented 3 years ago

I will close this pr.