-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transform bytes to byte[] instead of ByteString
- Loading branch information
Showing
3 changed files
with
32 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
25 changes: 25 additions & 0 deletions
25
generator/src/main/java/org/sudu/protogen/generator/type/BytesType.java
This file contains 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,25 @@ | ||
package org.sudu.protogen.generator.type; | ||
|
||
import com.google.protobuf.ByteString; | ||
import com.squareup.javapoet.ArrayTypeName; | ||
import com.squareup.javapoet.CodeBlock; | ||
import com.squareup.javapoet.TypeName; | ||
|
||
import java.util.Set; | ||
|
||
public class BytesType extends TypeModel { | ||
|
||
public BytesType() { | ||
super(ArrayTypeName.of(TypeName.BYTE)); | ||
} | ||
|
||
@Override | ||
public CodeBlock toGrpcTransformer(CodeBlock expr, Set<String> usedDefinitions) { | ||
return CodeBlock.of("$T.copyFrom($L)", ByteString.class, expr); | ||
} | ||
|
||
@Override | ||
public CodeBlock fromGrpcTransformer(CodeBlock expr, Set<String> usedDefinitions) { | ||
return CodeBlock.of("$L.toByteArray()", expr); | ||
} | ||
} |
This file contains 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