-
Notifications
You must be signed in to change notification settings - Fork 625
Initial implementation of firebase-encoders-proto #2206
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2f49eaa
Initial implementation of firebase-encoders-proto
vkryachko 8f7446f
Fix presubmit failures.
vkryachko a5f56fd
Add api.txt file.
vkryachko 1c646aa
Merge branch 'master' into vk.protobuf_encoder
vkryachko 17ce8be
Add float support.
vkryachko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Signature format: 2.0 | ||
package com.google.firebase.encoders.proto { | ||
|
||
public interface ProtoEnum { | ||
method public int getNumber(); | ||
} | ||
|
||
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS) public @interface Protobuf { | ||
method public abstract com.google.firebase.encoders.proto.Protobuf.IntEncoding intEncoding() default com.google.firebase.encoders.proto.Protobuf.IntEncoding.DEFAULT; | ||
method public abstract int tag(); | ||
} | ||
|
||
public enum Protobuf.IntEncoding { | ||
enum_constant public static final com.google.firebase.encoders.proto.Protobuf.IntEncoding DEFAULT; | ||
enum_constant public static final com.google.firebase.encoders.proto.Protobuf.IntEncoding FIXED; | ||
enum_constant public static final com.google.firebase.encoders.proto.Protobuf.IntEncoding SIGNED; | ||
} | ||
|
||
public class ProtobufEncoder { | ||
method public static com.google.firebase.encoders.proto.ProtobufEncoder.Builder builder(); | ||
method public void encode(@NonNull Object, @NonNull OutputStream); | ||
method @NonNull public byte[] encode(@NonNull Object); | ||
} | ||
|
||
public static final class ProtobufEncoder.Builder implements com.google.firebase.encoders.config.EncoderConfig<com.google.firebase.encoders.proto.ProtobufEncoder.Builder> { | ||
ctor public ProtobufEncoder.Builder(); | ||
method public com.google.firebase.encoders.proto.ProtobufEncoder build(); | ||
method @NonNull public com.google.firebase.encoders.proto.ProtobufEncoder.Builder configureWith(@NonNull com.google.firebase.encoders.config.Configurator); | ||
method @NonNull public <U> com.google.firebase.encoders.proto.ProtobufEncoder.Builder registerEncoder(@NonNull Class<U>, @NonNull com.google.firebase.encoders.ObjectEncoder<? super U>); | ||
method @NonNull public <U> com.google.firebase.encoders.proto.ProtobufEncoder.Builder registerEncoder(@NonNull Class<U>, @NonNull com.google.firebase.encoders.ValueEncoder<? super U>); | ||
method @NonNull public com.google.firebase.encoders.proto.ProtobufEncoder.Builder registerFallbackEncoder(@NonNull com.google.firebase.encoders.ObjectEncoder<Object>); | ||
} | ||
|
||
} | ||
|
55 changes: 55 additions & 0 deletions
55
encoders/firebase-encoders-proto/firebase-encoders-proto.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
plugins { | ||
id 'firebase-java-library' | ||
id 'com.google.protobuf' | ||
} | ||
|
||
firebaseLibrary { | ||
publishSources = true | ||
publishJavadoc = false | ||
} | ||
|
||
java { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
protobuf { | ||
protoc { | ||
artifact = "com.google.protobuf:protoc:$protocVersion" | ||
} | ||
} | ||
|
||
|
||
dependencies { | ||
implementation 'androidx.annotation:annotation:1.1.0' | ||
implementation project(':encoders:firebase-encoders') | ||
|
||
annotationProcessor project(':encoders:firebase-encoders-processor') | ||
|
||
testAnnotationProcessor project(':encoders:firebase-encoders-processor') | ||
|
||
testImplementation 'com.google.guava:guava:30.0-jre' | ||
testImplementation 'junit:junit:4.13.1' | ||
testImplementation 'com.google.protobuf:protobuf-java-util:3.11.0' | ||
testImplementation 'com.google.truth.extensions:truth-proto-extension:1.0' | ||
testImplementation "com.google.truth:truth:$googleTruthVersion" | ||
|
||
} | ||
|
||
tasks.withType(JavaCompile) { | ||
options.compilerArgs << "-Werror" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
version=0.1.0 |
49 changes: 49 additions & 0 deletions
49
...rs-proto/src/main/java/com/google/firebase/encoders/proto/LengthCountingOutputStream.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.encoders.proto; | ||
|
||
import androidx.annotation.NonNull; | ||
import java.io.OutputStream; | ||
|
||
/** OutputStream that only keeps track of the number of bytes written into it. */ | ||
final class LengthCountingOutputStream extends OutputStream { | ||
private long length = 0; | ||
|
||
@Override | ||
public void write(int b) { | ||
length++; | ||
} | ||
|
||
@Override | ||
public void write(byte[] b) { | ||
length += b.length; | ||
} | ||
|
||
@Override | ||
public void write(@NonNull byte[] b, int off, int len) { | ||
if ((off < 0) | ||
|| (off > b.length) | ||
|| (len < 0) | ||
|| ((off + len) > b.length) | ||
|| ((off + len) < 0)) { | ||
vkryachko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new IndexOutOfBoundsException(); | ||
} | ||
length += len; | ||
} | ||
|
||
long getLength() { | ||
return length; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...s/firebase-encoders-proto/src/main/java/com/google/firebase/encoders/proto/ProtoEnum.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.encoders.proto; | ||
|
||
/** | ||
* Base interface to be implemented by Enums that want to have control over their representation. | ||
*/ | ||
public interface ProtoEnum { | ||
|
||
/** Numeric representation of the Enum. */ | ||
int getNumber(); | ||
} |
36 changes: 36 additions & 0 deletions
36
...rs/firebase-encoders-proto/src/main/java/com/google/firebase/encoders/proto/Protobuf.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.encoders.proto; | ||
|
||
import com.google.firebase.encoders.annotations.ExtraProperty; | ||
|
||
/** | ||
* Protocol buffer field configuration that propagates into {@link | ||
* com.google.firebase.encoders.FieldDescriptor}s | ||
*/ | ||
@ExtraProperty | ||
public @interface Protobuf { | ||
/** Field tag */ | ||
int tag(); | ||
|
||
/** Specifies numeric field encoding. */ | ||
IntEncoding intEncoding() default IntEncoding.DEFAULT; | ||
|
||
enum IntEncoding { | ||
DEFAULT, | ||
SIGNED, | ||
FIXED | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.