Giter Site home page Giter Site logo

Comments (2)

PanagiotisDrakatos avatar PanagiotisDrakatos commented on June 16, 2024 1

@eduard-vasinskyi Brilliant!!!!!!!!!!! working like charm. Solved

from activej.

eduard-vasinskyi avatar eduard-vasinskyi commented on June 16, 2024

Hi, @PanagiotisDrakatos

The problem seems to be with chosen message encoding. You use ByteBufsDecoder#ofCrlfTerminatedBytes to decode messages. It expects messages to end with \r\n. However, your data may also contain \r\n, so deserializer does not decode the full message but rather part of it. You can verify that this is the case by modifying the loadData(Transaction) method:

private static @NotNull Promise<ByteBuf> loadData(Transaction transaction) {
    byte transaction_hash[] = encode.encode(transaction, 1024);
    for (int i = 0; i < transaction_hash.length - 1; i++) {
        if (transaction_hash[i] == '\r' && transaction_hash[i+1] == '\n'){
            throw new RuntimeException("CR LF conflict");
        }
    ByteBuf appendedBuf = ByteBufPool.append(ByteBuf.wrapForReading(transaction_hash), ByteBuf.wrapForReading("\r\n".getBytes()));
    return Promise.of(appendedBuf);
}

You could try to somehow escape the \r\n sequence in your data. Alternatively, you could use a different ByteBufsDecoder. One option is to use size-prefixed message encoding. For example, you could use ByteBufsDecoder.ofVarIntSizePrefixedBytes() as your DECODER. And then encode your message in loadData(Transaction) like this:

private static @NotNull Promise<ByteBuf> loadData(Transaction transaction) {
    byte transaction_hash[] = encode.encode(transaction, 1024);
    ByteBuf sizeBuf = ByteBufPool.allocate(2); // enough to serialize size 1024
    sizeBuf.writeVarInt(transaction_hash.length);
    ByteBuf appendedBuf = ByteBufPool.append(sizeBuf, ByteBuf.wrapForReading(transaction_hash));
    return Promise.of(appendedBuf);
}

from activej.

Related Issues (20)

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.