Skip to content

Commit

Permalink
Rename getLen -> getLength
Browse files Browse the repository at this point in the history
  • Loading branch information
ex3ndr committed Feb 10, 2014
1 parent 0d9af3a commit 6c00903
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
*.iml
.gradle
30 changes: 29 additions & 1 deletion src/main/java/org/telegram/tl/StreamingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,34 @@ public static void writeTLBytes(byte[] v, OutputStream stream) throws IOExceptio
}
}

/**
* Writing tl-bytes value
*
* @param v value
* @param stream destination stream
* @throws IOException
*/
public static void writeTLBytes(TLBytes v, OutputStream stream) throws IOException {
int startOffset = 1;
if (v.getLength() >= 254) {
startOffset = 4;
writeByte(254, stream);
writeByte(v.getLength() & 0xFF, stream);
writeByte((v.getLength() >> 8) & 0xFF, stream);
writeByte((v.getLength() >> 16) & 0xFF, stream);
} else {
writeByte(v.getLength(), stream);
}

writeByteArray(v.getData(), v.getOffset(), v.getLength(), stream);

int offset = (v.getLength() + startOffset) % 4;
if (offset != 0) {
int offsetCount = 4 - offset;
writeByteArray(new byte[offsetCount], stream);
}
}

/**
* Writing tl-object to stream
*
Expand Down Expand Up @@ -401,7 +429,7 @@ public static TLBytes readTLBytes(InputStream stream, TLContext context) throws
startOffset = 4;
}
TLBytes res = context.allocateBytes(count);
readBytes(res.getData(), res.getOffset(), res.getLen(), stream);
readBytes(res.getData(), res.getOffset(), res.getLength(), stream);

int offset = (count + startOffset) % 4;
if (offset != 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/telegram/tl/TLBytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public int getOffset() {
return offset;
}

public int getLen() {
public int getLength() {
return len;
}
}

0 comments on commit 6c00903

Please sign in to comment.