(ctx: EncodeContext, layout: ArrayLayout, arr: ReadonlyArray<unknown>, w: Writer)
| 3939 | } |
| 3940 | |
| 3941 | function encodeArray(ctx: EncodeContext, layout: ArrayLayout, arr: ReadonlyArray<unknown>, w: Writer) { |
| 3942 | const count = arr.length |
| 3943 | if (layout.rest.length === 0 && count > layout.elements.length) { |
| 3944 | issuePath[issuePathLen++] = layout.elements.length |
| 3945 | throw issueError( |
| 3946 | new SchemaIssue.UnexpectedKey(layout.ast, arr[layout.elements.length], ctx.options) |
| 3947 | ) |
| 3948 | } |
| 3949 | if (count < layout.minCount) { |
| 3950 | issuePath[issuePathLen++] = count |
| 3951 | throw issueError(new SchemaIssue.MissingKey(undefined)) |
| 3952 | } |
| 3953 | if (layout.hasCount) w.uvarint(count) |
| 3954 | if (count > 0) { |
| 3955 | const plan = runPlan(layout) |
| 3956 | if (plan !== null) { |
| 3957 | encodeStructRun(ctx, plan, arr, count, w) |
| 3958 | return |
| 3959 | } |
| 3960 | } |
| 3961 | const uniform = layout.uniform |
| 3962 | if (uniform !== undefined) { |
| 3963 | if (layout.uniformNumbers) { |
| 3964 | encodeNumberRun(ctx, arr, count, w) |
| 3965 | return |
| 3966 | } |
| 3967 | // Only a run field holding an array of strings hands over an intern table. |
| 3968 | const table = ctx.intern |
| 3969 | ctx.intern = undefined |
| 3970 | if (table !== undefined) { |
| 3971 | for (let i = 0; i < count; i++) { |
| 3972 | issuePath[issuePathLen++] = i |
| 3973 | encodeInterned(table, ctx, uniform, arr[i], w) |
| 3974 | issuePathLen-- |
| 3975 | } |
| 3976 | return |
| 3977 | } |
| 3978 | const inline = layout.uniformInline |
| 3979 | for (let i = 0; i < count; i++) { |
| 3980 | issuePath[issuePathLen++] = i |
| 3981 | if (inline) encodeValue(ctx, uniform, arr[i], w) |
| 3982 | else encodeSized(ctx, uniform, arr[i], w) |
| 3983 | issuePathLen-- |
| 3984 | } |
| 3985 | return |
| 3986 | } |
| 3987 | for (let i = 0; i < count; i++) { |
| 3988 | const slot = arraySlot(layout, i, count) |
| 3989 | issuePath[issuePathLen++] = i |
| 3990 | if (isInlineSlot(slot)) { |
| 3991 | encodeValue(ctx, slot, arr[i], w) |
| 3992 | } else { |
| 3993 | encodeSized(ctx, slot, arr[i], w) |
| 3994 | } |
| 3995 | issuePathLen-- |
| 3996 | } |
| 3997 | } |
| 3998 |
no test coverage detected