Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lp(encodeLpPacket): add encodeLpPacket support #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/net/named_data/jndn/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
package net.named_data.jndn;

import java.nio.ByteBuffer;
import java.util.ArrayList;

import net.named_data.jndn.encoding.EncodingException;
import net.named_data.jndn.encoding.WireFormat;
import net.named_data.jndn.encoding.SignatureHolder;
import net.named_data.jndn.lp.CongestionMark;
import net.named_data.jndn.lp.IncomingFaceId;
import net.named_data.jndn.lp.LpHeaderFiled;
import net.named_data.jndn.lp.LpPacket;
import net.named_data.jndn.util.Blob;
import net.named_data.jndn.util.ChangeCounter;
Expand Down Expand Up @@ -197,6 +200,42 @@ public Data(Data data)
public final Blob
getContent() { return content_; }

/**
* Count the number of LpHeaderFields of current LpPacket which bind to this Data
* @return the number of LpHeaderFields of current LpPacket which bind to this Data
*/
public int
countHeaderField() {
if (lpPacket_ == null)
return 0;
return lpPacket_.countHeaderFields();
}

/**
* Get all LpHeaderFields of current LpPacket which bind to this Data
* @return null if current Data has not bind any LpPacket
* >=0 presents all LpHeaderFields contains in current LpPacket which bind to this Data
*/
public ArrayList<LpHeaderFiled>
getHeaderFields() {
if (lpPacket_ == null)
return null;
return lpPacket_.getHeaderFields();
}

/**
* Add a LpHeaderField to current LpPacket which bind to this Data.
* This LpHeaderField will be encode to LpPacket when send current Data
*
* @param lpHeaderFiled The LpHeaderField want to add
*/
public void addHeaderFiled(LpHeaderFiled lpHeaderFiled) {
if (lpPacket_ == null) {
lpPacket_ = new LpPacket();
}
lpPacket_.addHeaderField(lpHeaderFiled);
}

/**
* Get the incoming face ID according to the incoming packet header.
* @return The incoming face ID. If not specified, return -1.
Expand All @@ -209,6 +248,18 @@ public Data(Data data)
return field == null ? -1 : field.getFaceId();
}

/**
* Set the CongestionMark, this will append to LpPacket's LpHeaderFields
*
* @param congestionMark congestion level
*/
public void
setCongestionMark(long congestionMark) {
CongestionMark congestionMark1 = new CongestionMark();
congestionMark1.setCongestionMark(congestionMark);
addHeaderFiled(congestionMark1);
}

/**
* Get the congestion mark according to the incoming packet header.
* @return The congestion mark. If not specified, return 0.
Expand Down
Loading