MCPcopy Create free account
hub / github.com/dagger/dagger / DecodePersistedObject

Method DecodePersistedObject

core/object.go:689–721  ·  view source on GitHub ↗
(
	ctx context.Context,
	dag *dagql.Server,
	_ uint64,
	_ *dagql.ResultCall,
	jsonBytes json.RawMessage,
)

Source from the content-addressed store, hash-verified

687}
688
689func (obj *ModuleObject) DecodePersistedObject(
690 ctx context.Context,
691 dag *dagql.Server,
692 _ uint64,
693 _ *dagql.ResultCall,
694 jsonBytes json.RawMessage,
695) (dagql.Typed, error) {
696 if obj == nil || obj.Module.Self() == nil || obj.TypeDef == nil {
697 return nil, fmt.Errorf("decode persisted module object: missing module/type definition")
698 }
699 var payload persistedModuleObjectPayload
700 if len(jsonBytes) > 0 {
701 if err := json.Unmarshal(jsonBytes, &payload); err != nil {
702 return nil, fmt.Errorf("decode persisted module object fields: %w", err)
703 }
704 }
705 fields := make(map[string]any, len(payload.Fields))
706 for name, encoded := range payload.Fields {
707 if _, ok := obj.TypeDef.FieldByOriginalName(name); ok && persistedModuleObjectValueHasCallID(encoded) {
708 return nil, fmt.Errorf("decode persisted module object field %q: unexpected raw call ID in semantic field", name)
709 }
710 decoded, err := decodePersistedModuleObjectValue(ctx, dag, encoded)
711 if err != nil {
712 return nil, fmt.Errorf("decode persisted module object field %q: %w", name, err)
713 }
714 fields[name] = decoded
715 }
716 return &ModuleObject{
717 Module: obj.Module,
718 TypeDef: obj.TypeDef,
719 Fields: fields,
720 }, nil
721}
722
723//nolint:gocyclo // intrinsically long state machine; refactoring would hurt clarity
724func encodePersistedModuleObjectValue(cache dagql.PersistedObjectCache, val any) (persistedModuleObjectValue, error) {

Calls 5

SelfMethod · 0.80
FieldByOriginalNameMethod · 0.80
UnmarshalMethod · 0.65