Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 812941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:16:49+00:00 2026-05-15T01:16:49+00:00

public class CustomProtocolDecoder extends CumulativeProtocolDecoder{ byte currentCmd = -1; int currentSize = -1; boolean

  • 0
public class CustomProtocolDecoder extends CumulativeProtocolDecoder{
    byte currentCmd = -1;
    int currentSize = -1;
    boolean isFirst = false;
    @Override
    protected boolean doDecode(IoSession is, ByteBuffer bb, ProtocolDecoderOutput pdo) throws Exception {
            if(currentCmd == -1)
            {
                currentCmd = bb.get();
                currentSize = Packet.getSize(currentCmd);
                isFirst = true;
            }
            while(bb.remaining() > 0)
            {
                if(!isFirst)
                {
                    currentCmd = bb.get();
                    currentSize = Packet.getSize(currentCmd);
                }
                else
                    isFirst = false;
                //System.err.println(currentCmd + " " + bb.remaining() + " " + currentSize);
                if(bb.remaining() >= currentSize - 1)
                {
                    Packet p = PacketDecoder.decodePacket(bb, currentCmd);
                    pdo.write(p);
                }
                else
                {
                    bb.flip();
                    return false;
                }
            }
            if(bb.remaining() == 0)
                return true;
            else
                return false;
    }
}

Anyone see anything wrong with this code? When a lot of packets are received at once, even when only one client is connected, one of them might get cut off at the end (12 bytes instead of 15 bytes, for example) which is obviously bad.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:16:49+00:00Added an answer on May 15, 2026 at 1:16 am

    I’m finding it a bit difficult to understand what protocol you’re trying to decode here. It’s definitely looking a bit confused in there 😉

    Are you writing something which expects many requests on the same connection? If so, then great, that’s what Mina’s good at …

    Normally, I’d expect a MINA decoder to be checking whether it’s got a complete message, and then, if not, to return the IoBuffer’s pointer back to the position it held at the start of the method.

    Normally a complete message would be determined by a delimiter, or perhaps a length field at the start of the message.

    The example provided in the api docs is pretty good.
    It’s looking for a delimiter of Carriage Return + Line Break:

    http://mina.apache.org/report/trunk/apidocs/org/apache/mina/filter/codec/CumulativeProtocolDecoder.html

    hth

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class SettingsActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /*
public class Browser1Activity extends Activity { TextView url; WebView ourBrow; @Override protected void onCreate(Bundle
public class SaveData extends Activity implements OnClickListener { private DataManipulator dh; static final int
public class MCQSample extends Activity implements OnClickListener{ TextView title; String gotBread; RadioGroup AnswerRG; int
public class abc<X extends Z> implements Iterable<X> { protected ArrayList<X> list; public Iterator<X> iterator()
public class IdAsync extends AsyncTask<String, Void, Void> { AlertDialog alertDialog = new AlertDialog.Builder(MainClass.this).create(); protected
public class HomeActivity extends Activity{ // public ArrayList<User> users1 = new ArrayList<User>(); @Override public
public class Boards : TabActivity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Tab);
public class upload extends Activity { private static final int CAMERA_REQUEST = 1888; private
public class CustomEditor : Editor { protected override void Render(HtmlTextWriter writer) { Toolbar topToolbar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.