Skip to content

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 5 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions encoders/firebase-encoders-proto/api.txt
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 encoders/firebase-encoders-proto/firebase-encoders-proto.gradle
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"
}
15 changes: 15 additions & 0 deletions encoders/firebase-encoders-proto/gradle.properties
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
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)) {
throw new IndexOutOfBoundsException();
}
length += len;
}

long getLength() {
return length;
}
}
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();
}
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
}
}
Loading