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

Function encode

packages/effect/src/unstable/encoding/Msgpack.ts:71–90  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

69 * @since 4.0.0
70 */
71export const encode = <IE = never, Done = unknown>(): Channel.Channel<
72 Arr.NonEmptyReadonlyArray<Uint8Array<ArrayBuffer>>,
73 IE | MsgPackError,
74 Done,
75 Arr.NonEmptyReadonlyArray<unknown>,
76 IE,
77 Done
78> =>
79 Channel.fromTransform((upstream, _scope) =>
80 Effect.sync(() => {
81 const packr = new Packr()
82 return Effect.flatMap(upstream, (chunk) => {
83 try {
84 return Effect.succeed(Arr.map(chunk, (item) => packr.pack(item) as Uint8Array<ArrayBuffer>))
85 } catch (cause) {
86 return Effect.fail(new MsgPackError({ kind: "Pack", cause }))
87 }
88 })
89 })
90 )
91
92/**
93 * Creates a MessagePack encoder channel for values of a schema.

Callers 2

encodeSchemaFunction · 0.70
duplexFunction · 0.70

Calls 5

packMethod · 0.80
syncMethod · 0.45
succeedMethod · 0.45
mapMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected