Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible improvement of json.RawMessage instead of LexiconTypeDecoder for unknown data #773

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions api/atproto/admindefs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions api/atproto/identitygetRecommendedDidCredentials.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions api/atproto/identitysignPlcOperation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/atproto/identitysubmitPlcOperation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions api/atproto/repoapplyWrites.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/atproto/repocreateRecord.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions api/atproto/repodescribeRepo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions api/atproto/repogetRecord.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions api/atproto/repolistRecords.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/atproto/repoputRecord.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions api/atproto/servercreateAccount.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions api/atproto/servercreateSession.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions api/atproto/servergetSession.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions api/atproto/serverrefreshSession.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions automod/capture/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/bluesky-social/indigo/atproto/identity"
"github.com/bluesky-social/indigo/atproto/syntax"
"github.com/bluesky-social/indigo/automod"
lexutil "github.com/bluesky-social/indigo/lex/util"
"github.com/bluesky-social/indigo/xrpc"
)

Expand Down Expand Up @@ -36,8 +37,12 @@ func FetchAndProcessRecord(ctx context.Context, eng *automod.Engine, aturi synta
return fmt.Errorf("expected a CID in getRecord response")
}
recCID := syntax.CID(*out.Cid)
var ltd lexutil.LexiconTypeDecoder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be cleaner to use util.JsonDecodeValue()
maybe make a utility function that returns (cbg.CBORMarshaler, error) if we want better than (any, error) ?

if err = ltd.UnmarshalJSON(*out.Value); err != nil {
return err
}
recBuf := new(bytes.Buffer)
if err := out.Value.Val.MarshalCBOR(recBuf); err != nil {
if err := ltd.Val.MarshalCBOR(recBuf); err != nil {
return err
}
recBytes := recBuf.Bytes()
Expand Down Expand Up @@ -85,8 +90,12 @@ func FetchAndProcessRecent(ctx context.Context, eng *automod.Engine, atid syntax
return fmt.Errorf("parsing PDS record response: %v", err)
}
recCID := syntax.CID(rec.Cid)
var ltd lexutil.LexiconTypeDecoder
if err = ltd.UnmarshalJSON(*rec.Value); err != nil {
return err
}
recBuf := new(bytes.Buffer)
if err := rec.Value.Val.MarshalCBOR(recBuf); err != nil {
if err := ltd.Val.MarshalCBOR(recBuf); err != nil {
return err
}
recBytes := recBuf.Bytes()
Expand Down
Loading
Loading