Giter VIP home page Giter VIP logo

protoparser's People

Contributors

alanpaulin avatar anistor avatar danielheckrath avatar jakewharton avatar raskasa avatar swankjesse avatar tbroyer avatar zachmargolis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

protoparser's Issues

Message Inside Extensions Fails Parsing

package validation;
extend google.protobuf.FieldOptions {
  optional Range range = 12345;
}
message Range {
  optional double min = 1;
  optional double max = 2;
}
package things;
message Foo {
  optional int32 bar = 1 [
      (validation.range).min = 1,
      (validation.range).max = 100,
      default = 20
  ];
}

Fails upon hitting the . after the first (validation.range) in ProtoSchemaParser's readName.

cc: @swankjesse @danrice-square

Easy fix would be to add something like this:

c = peekChar();
if (c == '.') {
  pos++;
  optionName += "." + readWord();
}

Which turns the Field's extension map into {validation.range.min: 1, validation.range.max: 100, default: 20}.

But we should probably be smarter about the type and turn it into {validation.range: Range{min:1, max:100}, default: 20}, right?

Publish project javadocs?

It would be nice to have javadocs available online. I usually do this on gh-pages branch for github, but I am sure there are other ways. Can then link javadocs from README.

Provide More Convenient Option Lookup

Providing a List<Option> is accurate to the source, but annoying for downstream consumers. Converting to a Map<String, Object> is also a pain for consumers. There needs to be an easy map-like lookup of option values.

Maybe something like this?

public final class OptionList implements List<Option> {
  public Object get(String key) { .. }
  public String getString(String key) { .. }
  public Option getOption(String key) { .. }
}

Simple solution would be to offer

public static Object getOption(List<Option> options, String key)

that iterates every time.

MessageType fullName error

file.proto
package example.simple;

message Message1 {
optional string bestHuman = 1;
}
this proto file will generate example.simple.file.Message1
by google proto compiler

but square/protoparser will
getFullyQualifiedName as example.simple.Message1

Include Primitive Type Constants

The primitive types should be available as string constants somewhere. Maybe on a Types class which also has convenience methods like isPrimitive(String).

Parse IDL while has default value will throw exception

idl code as follow:
"package tutorial;" +
"option java_package = "com.example.tutorial";"
"option java_outer_classname = "AddressBookProtos";"
" message PhoneNumber {"
"required int32 number = 1 [default = 1];"
"}";

while call field.getDefault(); will throw cast exception due to integer can not cast to String

public String getDefault() {
  Option defaultOption = Option.findByName(options, "default");
  return defaultOption != null ? (String) defaultOption.getValue() : null;
}

Builders on elements.

It's tedious constructing a message, for example. The tests are littered with a bunch of default values for everything.

`MessageType.Field.isPacked()` broke from 3.1.4 -> 3.1.5

First of all, thank you for this great library. It has worked like a charm so far; I use it for Jackson protobuf data format backend (https://github.com/FasterXML/jackson-dataformat-protobuf).

So. It looks like handling of isPacked() method in MessageType.Field broke between 3.1.4 and 3.1.5.
I noticed when trying to upgrade version, when couple of unit tests on my end started failing. Looking at changelog and set of tests failing, it looked like somehow 'packed' option was not being detected.

However: looks like parser actually finds options as expected. The problem is rather that it seems to coerce type into Boolean.TRUE instead of String "true". Unfortunately isPacked() assumes a String, and equals() fails between the two representations.
I would guess isDeprecated() is broken similarly.

I can work around the problem locally by using "getOptions()", doing explicit checks, but it would make sense to fix the convenient accessor as well.

com.squareup.protoparser.EnumType$Value cannot be cast to java.lang.String

Hi, first of all, thank you for your contribution
The thing is when I try to check a MessageType.Field has default or not
I use => if (field.getDefault() != null)
but I get exception:
com.squareup.protoparser.EnumType$Value cannot be cast to java.lang.String

the original .proto defined is
optional PhoneType type = 2 [default = HOME];
(same as official example Person message: https://developers.google.com/protocol-buffers/docs/javatutorial)

is any misunderstanding or mistake in my code?
(my source code https://github.com/cecol/protobuf-to-avro/blob/dev/src/main/java/wilber/com/transform/ProtoSchema.java)

comment parse like official protobuf with heading comment and trailing comment

comment should like official protobuf with heading comment and trailing comment

 /**
       * <code>optional string leading_comments = 3;</code>
       *
       * <pre>
       * If this SourceCodeInfo represents a complete declaration, these are any
       * comments appearing before and after the declaration which appear to be
       * attached to the declaration.
       * A series of line comments appearing on consecutive lines, with no other
       * tokens appearing on those lines, will be treated as a single comment.
       * Only the comment content is provided; comment markers (e.g. //) are
       * stripped out.  For block comments, leading whitespace and an asterisk
       * will be stripped from the beginning of each line other than the first.
       * Newlines are included in the output.
       * Examples:
       *   optional int32 foo = 1;  // Comment attached to foo.
       *   // Comment attached to bar.
       *   optional int32 bar = 2;
       *   optional string baz = 3;
       *   // Comment attached to baz.
       *   // Another line attached to baz.
       *   // Comment attached to qux.
       *   //
       *   // Another line attached to qux.
       *   optional double qux = 4;
       *   optional string corge = 5;
       *   /&#42; Block comment attached
       *    * to corge.  Leading asterisks
       *    * will be removed. *&#47;
       *   /&#42; Block comment attached to
       *    * grault. *&#47;
       *   optional int32 grault = 6;
       * </pre>
       */

Expected declaration format for syntax detection is wrong

The implementation from #77 expects the syntax declaration to be in this form:

syntax "proto3";

while the proto3 documentation states that the syntax declaration is

syntax = "proto3";

If I use protoparser to parse the proto3 message from the proto3 spec it fails with the following exception

syntax = "proto3";

message SearchRequest {
  string query = 1;
  int32 page_number = 2;
  int32 result_per_page = 3;
}

Exception in thread "main" java.lang.AssertionError
    at com.squareup.protoparser.ProtoParser.readQuotedString(ProtoParser.java:602)
    at com.squareup.protoparser.ProtoParser.readDeclaration(ProtoParser.java:134)
    at com.squareup.protoparser.ProtoParser.readProtoFile(ProtoParser.java:92)

Documentation leading whitespace ignored.

// A --> B
//  \
//   C
message Test {}

Should result in:

A --> B
 \
  C

and not:

A --> B
\
C

We need to be less-eager about nom-ing all the leading whitespace. There are only a few leading versions of comments so we can be a bit more smart. Something like this:

^\s+(// ?|/\*\* ?|\* ?)

Add support for groups

I know groups are deprecated but are still part of the spec. Can we add support for them for the sake of compatibility with existing proto schemas?

Fields tag can have duplicated values

message Foo {
  optional int32 bar = 1;
  optional int32 quix = 1;
}

Compiles just fine.

This should only be allowed if allow_alias = true.

message Foo {
  option allow_alias = true;
  optional int32 bar = 1;
  optional int32 quix = 1;
}

Syntax detection

And model property. Probably an enum.

Valid values:

syntax = "proto3"
syntax = "proto2"

Source files without license headers

Hi

The following source files are without license headers:

./src/main/java/com/squareup/protoparser/DataType.java
./src/main/java/com/squareup/protoparser/EnumConstantElement.java
./src/main/java/com/squareup/protoparser/EnumElement.java
./src/main/java/com/squareup/protoparser/ExtendElement.java
./src/main/java/com/squareup/protoparser/ExtensionsElement.java
./src/main/java/com/squareup/protoparser/FieldElement.java
./src/main/java/com/squareup/protoparser/MessageElement.java
./src/main/java/com/squareup/protoparser/OneOfElement.java
./src/main/java/com/squareup/protoparser/OptionElement.java
./src/main/java/com/squareup/protoparser/ProtoFile.java
./src/main/java/com/squareup/protoparser/ProtoParser.java
./src/main/java/com/squareup/protoparser/RpcElement.java
./src/main/java/com/squareup/protoparser/ServiceElement.java
./src/main/java/com/squareup/protoparser/TypeElement.java

./src/test/java/com/squareup/protoparser/DataTypeTest.java
./src/test/java/com/squareup/protoparser/EnumConstantElementTest.java
./src/test/java/com/squareup/protoparser/EnumElementTest.java
./src/test/java/com/squareup/protoparser/ExtendElementTest.java
./src/test/java/com/squareup/protoparser/ExtensionsElementTest.java
./src/test/java/com/squareup/protoparser/FieldElementTest.java
./src/test/java/com/squareup/protoparser/MessageElementTest.java
./src/test/java/com/squareup/protoparser/OneOfElementTest.java
./src/test/java/com/squareup/protoparser/OptionElementTest.java
./src/test/java/com/squareup/protoparser/ParsingTester.java
./src/test/java/com/squareup/protoparser/ProtoFileTest.java
./src/test/java/com/squareup/protoparser/RpcElementTest.java
./src/test/java/com/squareup/protoparser/ServiceElementTest.java
./src/test/java/com/squareup/protoparser/TestUtils.java
./src/test/java/com/squareup/protoparser/UtilsTest.java

Please, confirm the licensing of code and/or content/s, and add license headers
https://fedoraproject.org/wiki/Packaging:LicensingGuidelines?rd=Packaging/LicensingGuidelines#License_Clarification

The following source files contains this license header

// Copyright 2013 Square, Inc.

./src/main/java/com/squareup/protoparser/Utils.java
./src/test/java/com/squareup/protoparser/ProtoParserTest.java

can You change with

/*
 * Copyright 2013 Square, Inc.
 *
 * 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.
 */

?

Thanks in advance
Regards

The option allow_alias is not respected for enums

Here is a simple example. Thanks.

option java_package = "com.test";
option java_generic_services = false;
option java_outer_classname = "ClientCode";

enum ClientCode {
    option allow_alias = true;
    T_1 = 1;
    T_0 = 1;
}

Nested Extend Declarations Ignored

Failing test:

  @Test public void extendInMessage() throws Exception {
    String proto = ""
        + "message Bar {\n"
        + "  extend Foo {\n"
        + "    optional int32 bar = 126;\n"
        + "  }\n"
        + "}";
    List<ExtendDeclaration> extendDeclarations = new ArrayList<ExtendDeclaration>();
    extendDeclarations.add(new ExtendDeclaration("Foo", "Foo", "",
        Arrays.asList(new MessageType.Field(Label.OPTIONAL, "int32", "bar", 126, "", NO_OPTIONS))));
    Type messageType =
        new MessageType("Bar", "Bar", "", NO_FIELDS, NO_TYPES, NO_EXTENSIONS, NO_OPTIONS);
    ProtoFile expected =
        new ProtoFile("descriptor.proto", null, NO_STRINGS, NO_STRINGS, Arrays.asList(messageType),
            NO_SERVICES, NO_OPTIONS, extendDeclarations);
    assertThat(ProtoSchemaParser.parse("descriptor.proto", proto))
        .isEqualTo(expected);
  }

Enforce enum value tag uniqueness in scope

Enum values are scoped as siblings to the enum, not children. As such, value tags must be unique within the parent scope.

Throw an exception on:

message Foo {
  enum Bar {
    HELLO = 1;
  }
  enum Baz {
    GOODBYE = 1;
  }
}

Absence of whitespace causing parsing issues

String proto = ""
    + "package example;"
    + ""
    + "message A {"
    + "  message B {}"
    + "}"
    + "message C {"
    + "  optional A.B ab = 1;"
    + "}";
ProtoSchemaParser.parse("test.proto", proto);
java.lang.IllegalStateException: Syntax error in test.proto at 1:74: unexpected end of file
    at com.squareup.protoparser.ProtoSchemaParser.unexpected(ProtoSchemaParser.java:739)
    at com.squareup.protoparser.ProtoSchemaParser.peekChar(ProtoSchemaParser.java:515)
    at com.squareup.protoparser.ProtoSchemaParser.readMessage(ProtoSchemaParser.java:216)
    at com.squareup.protoparser.ProtoSchemaParser.readDeclaration(ProtoSchemaParser.java:163)
    at com.squareup.protoparser.ProtoSchemaParser.readProtoFile(ProtoSchemaParser.java:119)
    at com.squareup.protoparser.ProtoSchemaParser.parse(ProtoSchemaParser.java:42)

Trailing doc is assigned to the following field

When parsing:

message DescriptorProto {
  optional string name = 1;
  optional string doc = 8; // Doc string for generated code.

  repeated FieldDescriptorProto field = 2;
}

the doc string "Doc string for generated code." is associated with the field 'field' instead of the field 'doc'.

FieldElement cardinality

Thank you for making this package.

I think the FieldElement type should hold information about whether the value is of a repeated type. (in protobuf lib called cardinality).
Let me know if you accept a PR for this (and if you agree that it is missing)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.