facebookarchive / swift

An annotation-based Java library for creating Thrift serializable types and services.
Apache License 2.0
900 stars 297 forks source link

Allows codec to work with auto-value types #274

Closed codefromthecrypt closed 9 years ago

codefromthecrypt commented 9 years ago

Auto-Value writes immutable value types based on a user defined abstract class. It also supports generating factories, based on a user-defined interface. The following change adjusts swift codec to work both reflectively and via ASM.

Here's an example type that works following this change:

@AutoValue
@ThriftStruct(value = "LogEntry", builder = AutoValue_LogEntry.Builder.class)
public abstract class LogEntry {

  public static Builder builder() {
    return new AutoValue_LogEntry.Builder();
  }

  @ThriftField(value = 1)
  public abstract String category();

  @ThriftField(value = 2)
  public abstract String message();

  @AutoValue.Builder
  public interface Builder {

    @ThriftField(value = 1)
    Builder category(String category);

    @ThriftField(value = 2)
    Builder message(String message);

    @ThriftConstructor
    LogEntry build();
  }
}

The notable change for ASM is that generated codecs are now placed in the same package as the value type, and defined in the same classloader. Also, this makes sure we use the correct injection method (ex. from the implementing class as opposed to the interface).

Tests pass and I've also verified with zipkin.

Closes #273

codefromthecrypt commented 9 years ago

fyi @kristofa @spencergibb @eamonnmcmanus

codefromthecrypt commented 9 years ago

weird.. all the comments got stripped.. anyway @andrewcox lemme know if you've anything needed before merge.

codefromthecrypt commented 9 years ago

any timeframe on this? I'd love to take out my build hack https://github.com/openzipkin/zipkin-java/blob/master/swift-codec/pom.xml

codefromthecrypt commented 9 years ago

hate to nag, but is this project on pause?