Giter VIP home page Giter VIP logo

jserial's People

Contributors

ebirukov avatar jkeys089 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jserial's Issues

Use deserialization from byte stream instead of byte slice

@jkeys089 I really liked your implementation of the java serialization protocol, it is simple and convenient. But I need to use deserialization for a stream of bytes. The bytes of the serialized objects that I have to deserialize are part of the data in the stream. The stream itself contains data bytes before and after the bytes of the serialized object. Because Since this implementation uses a slice of bytes, I cannot extract the data bytes related to the deserialized object. As a solution, I need an io.Reader, or even better a bufio.Reader, so that I can use buffered stream features like unreadByte and Peek.
The java serialization protocol does not contain end-of-byte markers for the serialized object in the stream. It is necessary to be able to complete the deserialization procedure and ignore the "unknown type" error of the serializedObjectParser.content method

Read single object

Thanks for the great library!
Currently the implementation expects to always read to the end of the stream.

jserial/deserialize.go

Lines 356 to 365 in afb2f73

// end check has next byte in stream.
func (sop *SerializedObjectParser) end() bool {
if sop.rd.Buffered() == 0 {
_, eof := sop.rd.Peek(1)
return eof != nil
}
return false
}

I have a case where the stream contains other stuff in addition to the serialised java object. And I don't have a size of the java object to be able to r = io.LimitReader(r,size) before attempting to parse.
I.e. I want to be able to do something like:

sop := jserial.NewSerializedObjectParser(r)
minimal, err := sop.ParseSingleSerializedObjectMinimal()
if err != nil {
    return err
}
r.Read(buf)

where buf would be populated with content right after the first serialised object
minimal would then be the single deserialised object, instead of a slice/jsonArray

Testing log4j 1.17 socket appender, can only parse the first document

Hi,
I'm glad I found this library to experiment with.

I am using the library to try reading log4j logging event. I read the connection with bufio.NewReader then fed to jserial.NewSerializedObjectParser(r)

While single item worked well, if I am trying to send multiple events at once, ie. having 2 log.debug("Hello"); in the file below, it would fail to parse anything other than the first document.

logstash-input-log4j tester

I tried peeking it, while I have EOF error, it clearly still have data behind the EOF.

Here is the log.

2023/03/07 10:21:27 Peeked: [4 109 97 105 110 112 119 4 0 0 39 16 112 120 121]
2023/03/07 10:21:27 Error parsing object: [] error reading uint16: EOF
2023/03/07 10:21:27 Error peeking reader: EOF
2023/03/07 10:21:27 Peeked: []
2023/03/07 10:21:27 Received unserialized content:
 {"@":["AAAnEA==",null],"categoryName":"sender","class":{},"extends":{"org.apache.log4j.spi.LoggingEvent":{"@":["AAAnEA==",null],"categoryName":"sender","locationInfo":null,"mdcCopy":null,"mdcCopyLookupRequired":false,"ndc":null,"ndcLookupRequired":false,"renderedMessage":"Hello","threadName":"main","throwableInfo":null,"timeStamp":1678155687937}},"locationInfo":null,"mdcCopy":null,"mdcCopyLookupRequired":false,"ndc":null,"ndcLookupRequired":false,"renderedMessage":"Hello","threadName":"main","throwableInfo":null,"timeStamp":1678155687937}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.