Skip to content

Commit

Permalink
<feat: added copyright header>
Browse files Browse the repository at this point in the history
  • Loading branch information
Auties00 committed May 5, 2024
1 parent e39b484 commit 327748a
Showing 1 changed file with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd

// I'm not sure if the LICENSE copyright header is necessary as only two methods in this class are taken from Google's source code
// But just to be sure I included it

package it.auties.protobuf.stream;

import it.auties.protobuf.exception.ProtobufDeserializationException;
Expand Down Expand Up @@ -183,6 +193,8 @@ public int readInt32() {
return readInt32Unchecked();
}

// Source: https://github.com/protocolbuffers/protobuf/blob/main/java/core/src/main/java/com/google/protobuf/CodedInputStream.java
// Fastest implementation I could find
private int readInt32Unchecked() {
fspath:
{
Expand Down Expand Up @@ -219,7 +231,9 @@ private int readInt32Unchecked() {

return (int) readVarInt64Slow();
}


// Source: https://github.com/protocolbuffers/protobuf/blob/main/java/core/src/main/java/com/google/protobuf/CodedInputStream.java
// Fastest implementation I could find
public long readInt64() {
if(wireType != ProtobufWireType.WIRE_TYPE_VAR_INT) {
throw ProtobufDeserializationException.invalidWireType(wireType);
Expand Down Expand Up @@ -306,7 +320,10 @@ public int readFixed32() {

byte[] buffer = this.buffer;
this.pos = tempPos + 4;
return buffer[tempPos] & 255 | (buffer[tempPos + 1] & 255) << 8 | (buffer[tempPos + 2] & 255) << 16 | (buffer[tempPos + 3] & 255) << 24;
return buffer[tempPos] & 255
| (buffer[tempPos + 1] & 255) << 8
| (buffer[tempPos + 2] & 255) << 16
| (buffer[tempPos + 3] & 255) << 24;
}

public long readFixed64() {
Expand All @@ -321,7 +338,14 @@ public long readFixed64() {

byte[] buffer = this.buffer;
this.pos = tempPos + 8;
return (long) buffer[tempPos] & 255L | ((long) buffer[tempPos + 1] & 255L) << 8 | ((long) buffer[tempPos + 2] & 255L) << 16 | ((long) buffer[tempPos + 3] & 255L) << 24 | ((long) buffer[tempPos + 4] & 255L) << 32 | ((long) buffer[tempPos + 5] & 255L) << 40 | ((long) buffer[tempPos + 6] & 255L) << 48 | ((long) buffer[tempPos + 7] & 255L) << 56;
return (long) buffer[tempPos] & 255L
| ((long) buffer[tempPos + 1] & 255L) << 8
| ((long) buffer[tempPos + 2] & 255L) << 16
| ((long) buffer[tempPos + 3] & 255L) << 24
| ((long) buffer[tempPos + 4] & 255L) << 32
| ((long) buffer[tempPos + 5] & 255L) << 40
| ((long) buffer[tempPos + 6] & 255L) << 48
| ((long) buffer[tempPos + 7] & 255L) << 56;
}

public byte readByte() {
Expand Down

0 comments on commit 327748a

Please sign in to comment.