Skip to content

Commit

Permalink
added check for partial messages
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Dec 8, 2017
1 parent 9e0d084 commit 662005b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build/Message.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,8 @@ export declare class Message {
* serializes this message into a buffer
*/
serialize(): Buffer;
/**
* Checks if this message is part of a blockwise transfer
*/
isPartialMessage(): boolean;
}
13 changes: 13 additions & 0 deletions build/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ class Message {
}
return ret;
}
/**
* Checks if this message is part of a blockwise transfer
*/
isPartialMessage() {
// TODO: can we put the codes in an enum?
const block1option = this.options.find(o => o.code === 27 /* Block1 */);
const block2option = this.options.find(o => o.code === 23 /* Block2 */);
if (this.code.isRequest() && block1option != null)
return true;
if (this.code.isResponse() && block2option != null)
return true;
return false;
}
}
exports.Message = Message;
/*
Expand Down
13 changes: 13 additions & 0 deletions src/Message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Option } from "./Option";
import { fail } from "assert";

export enum MessageType {
CON = 0, // Confirmable
Expand Down Expand Up @@ -202,6 +203,18 @@ export class Message {
return ret;
}

/**
* Checks if this message is part of a blockwise transfer
*/
public isPartialMessage(): boolean {
// TODO: can we put the codes in an enum?
const block1option = this.options.find(o => o.code === 27 /* Block1 */);
const block2option = this.options.find(o => o.code === 23 /* Block2 */);
if (this.code.isRequest() && block1option != null) return true;
if (this.code.isResponse() && block2option != null) return true;
return false;
}

}

/*
Expand Down

0 comments on commit 662005b

Please sign in to comment.