-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #903 from samchon/features/encode
Fix #901 - `protobuf.encode<T>()` be returned when union type comes.
- Loading branch information
Showing
76 changed files
with
893 additions
and
404 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
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
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
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
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
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
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
40 changes: 40 additions & 0 deletions
40
test/src/features/issues/test_issue_901_protobuf_encode_union_problem.ts
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,40 @@ | ||
import typia, { tags } from "typia"; | ||
|
||
import { protobuf_equal_to } from "../../helpers/protobuf_equal_to"; | ||
|
||
export const test_issue_901_protobuf_encode_union_problem = () => { | ||
const customer: Customer = typia.random<Customer>(); | ||
const encoded: Uint8Array = typia.protobuf.encode<Customer>(customer); | ||
const decoded: Customer = typia.protobuf.decode<Customer>(encoded); | ||
|
||
if (false === protobuf_equal_to("equal")(customer, decoded)) | ||
throw new Error( | ||
"Bug on typia.protobuf.encode(): failed to encode the union type.", | ||
); | ||
}; | ||
|
||
interface Customer { | ||
id: number & tags.Type<"int32">; | ||
email: string & tags.Format<"email">; | ||
name: string; | ||
pet: Cat | Dog; | ||
memo: Map<string, string>; | ||
logins: Array<CustomerLogin> & tags.MinItems<1>; | ||
} | ||
interface Cat { | ||
type: "cat"; | ||
name: string; | ||
ribbon: boolean; | ||
} | ||
interface Dog { | ||
type: "dog"; | ||
name: string; | ||
hunt: boolean; | ||
} | ||
interface CustomerLogin { | ||
success: boolean; | ||
href: string & tags.Format<"url">; | ||
referrer: string & tags.Format<"url">; | ||
ip: string & (tags.Format<"ipv4"> | tags.Format<"ipv6">); | ||
time: string & tags.Format<"date-time">; | ||
} |
Oops, something went wrong.