JuliaIO / ProtoBuf.jl

Julia protobuf implementation
Other
205 stars 55 forks source link

Add `position` method for encoder/decoder #218

Open wildart opened 1 year ago

wildart commented 1 year ago

Is it possible to abstract position and perform it on encoder/decoder object instead of io property? Its assumed that io object type would have a position implemented, but for socket types (pipe & network) it's not the case.

Here is an example of a generated encoder code

function PB.encode(e::PB.AbstractProtoEncoder, x::Point)
    initpos = position(e.io)
    x.latitude != zero(Int32) && PB.encode(e, 1, x.latitude)
    x.longitude != zero(Int32) && PB.encode(e, 2, x.longitude)
    return position(e.io) - initpos
end

If I want to implement a socket-based encoder I may need to handle position requests to encoder itself which would handle some additional metadata exchange to get the message size or some terminator by wire to estimate a position within protobuf data stream.