rfc5424 icon indicating copy to clipboard operation
rfc5424 copied to clipboard

Added function that marshals message into a given byte buffer.

Open altenhof opened this issue 8 years ago • 5 comments

Should alllow us to pool byte buffers across multiple calls.

altenhof avatar Jan 02 '17 12:01 altenhof

Thanks for your PR. This looks like it should be named WriteTo and implement the io.WriterTo interface, eh?

crewjam avatar Jan 02 '17 13:01 crewjam

Unfortunately, WriteTo is already taken, defined in stream.go, which, btw, does use Writer and not WriterTo as an argument.

So, what about MarshalTo(w io.Writer)?

altenhof avatar Jan 02 '17 13:01 altenhof

I'm hesitant to use a "wrong" name for a function that has a standard defined interface like WriterTo.

Perhaps a solution is to change the existing stream format WriteTo() to a different name, or attach it to a helper struct. That way the function you wrote can be (correctly) named WriteTo. I think that makes the object behave closer to the way people expect.

crewjam avatar Jan 03 '17 16:01 crewjam

I'm not sure what the "right" name for such a function would be, but maybe I just shortly recap what my initial idea was:

I'm using the library within a component that does "log forwarding", i.e. get log messages in syslog format, transforms them and then forwards them to another syslog endpoint. As I'm expecting fairly heavy loads (several thousand msg/sec), I wanted to have a way to "reuse" bytes.Buffer instances (using sync.Pool) when it comes to forwarding the messages. Right now, MarshalBinary allocate a new bytes.Buffer for every call.

So, I'm not that much looking for a WriteTo function that could write to a io.Writer interface, but for a MarshalTo marshalling the message into a bytes.Buffer. I would have done it "myself", but then I would have to duplicate most of the code in marshal.go.

So how shall we proceed?

altenhof avatar Jan 04 '17 09:01 altenhof

Any update on this?

altenhof avatar Jan 31 '17 10:01 altenhof