Skip to content

Commit

Permalink
Size in TypeValue, IntegerTypeValue, ShortTypeValue
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlopez committed Jul 17, 2011
1 parent d54bc3a commit 568785c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion AjVars/IntegerTypeValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

public class IntegerTypeValue : TypeValue
{
public override short Size { get { return 4; } }

public override object ParseString(string text)
{
return Int32.Parse(text);
Expand All @@ -15,7 +17,7 @@ public override object ParseString(string text)
public override byte[] ToBytes(object obj)
{
int value = (int)obj;
byte[] bytes = new byte[4];
byte[] bytes = new byte[this.Size];
bytes[0] = (byte)((value >> 24) & 0xff);
bytes[1] = (byte)((value >> 16) & 0xff);
bytes[2] = (byte)((value >> 8) & 0xff);
Expand Down
4 changes: 3 additions & 1 deletion AjVars/ShortTypeValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

public class ShortTypeValue : TypeValue
{
public override short Size { get { return 2; } }

public override object ParseString(string text)
{
return Int16.Parse(text);
Expand All @@ -15,7 +17,7 @@ public override object ParseString(string text)
public override byte[] ToBytes(object obj)
{
short value = (short)obj;
byte[] bytes = new byte[2];
byte[] bytes = new byte[this.Size];
bytes[0] = (byte)((value >> 8) & 0xff);
bytes[1] = (byte)(value & 0xff);
return bytes;
Expand Down
2 changes: 2 additions & 0 deletions AjVars/TypeValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

public abstract class TypeValue
{
public abstract short Size { get; }

public abstract object ParseString(string text);

public abstract byte[] ToBytes(object obj);
Expand Down

0 comments on commit 568785c

Please sign in to comment.