MCPcopy Create free account
hub / github.com/Effect-TS/effect / encodeRunRow

Function encodeRunRow

packages/effect/src/encoding/SchemaBinary.ts:3858–3931  ·  view source on GitHub ↗
(
  ctx: EncodeContext,
  plan: RunPlan,
  shapes: Array<number>,
  tables: Array<InternWrite | undefined>,
  value: unknown,
  w: Writer
)

Source from the content-addressed store, hash-verified

3856}
3857
3858function encodeRunRow(
3859 ctx: EncodeContext,
3860 plan: RunPlan,
3861 shapes: Array<number>,
3862 tables: Array<InternWrite | undefined>,
3863 value: unknown,
3864 w: Writer
3865) {
3866 const struct = plan.struct
3867 const obj = value as Record<string, unknown>
3868 const fields = struct.fields
3869 let pairs: Array<ExtraPair> | undefined
3870 if (struct.extra.length > 0) {
3871 const found = extraPairs(ctx, struct, obj)
3872 if (found.length > 0) pairs = found
3873 }
3874 const wide = !plan.shapes
3875 let mask = pairs === undefined ? 0 : RUN_EXTRA_BIT
3876 const presenceMask = runPresenceMask(plan, obj)
3877 if (presenceMask !== undefined) {
3878 mask = presenceMask
3879 } else {
3880 for (let i = 0; i < fields.length; i++) {
3881 const field = fields[i]
3882 if (Object.hasOwn(obj, field.name)) {
3883 if (!wide) mask |= 1 << i
3884 } else if (!field.optional) {
3885 issuePath[issuePathLen++] = field.name
3886 throw issueError(new SchemaIssue.MissingKey(field.annotations))
3887 }
3888 }
3889 }
3890 let shape = -1
3891 for (let i = 0; i < shapes.length; i++) {
3892 if (shapes[i] === mask) {
3893 shape = i
3894 break
3895 }
3896 }
3897 if (shape >= 0) {
3898 w.uvarint(shape + 1)
3899 } else {
3900 w.uvarint(0)
3901 if (!wide) shapes.push(mask)
3902 }
3903 const declare = shape < 0
3904 // Fingerprint mode proves both layouts match, so a declared shape is the
3905 // presence mask instead of a field id list.
3906 const positionalShape = ctx.positional && !wide
3907 if (declare && positionalShape) w.uvarint(mask)
3908 if (pairs !== undefined) {
3909 if (declare && !positionalShape) w.uvarint(0)
3910 const mark = w.beginSized()
3911 encodeExtraPairs(ctx, pairs, obj, w)
3912 w.endSizedRun(mark)
3913 }
3914 for (let i = 0; i < fields.length; i++) {
3915 const field = fields[i]

Callers 1

encodeStructRunFunction · 0.85

Calls 11

extraPairsFunction · 0.85
runPresenceMaskFunction · 0.85
issueErrorFunction · 0.85
encodeExtraPairsFunction · 0.85
encodeInternedFunction · 0.85
internWriteFunction · 0.85
beginSizedMethod · 0.80
endSizedRunMethod · 0.80
encodeValueFunction · 0.70
pushMethod · 0.65
uvarintMethod · 0.45

Tested by

no test coverage detected