-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from xmidt-org/denopink/patch/wrp-DecodeEntit…
…y-doesnt-honor-contentType patch: DecodeEntity doesn't honor contentType
- Loading branch information
Showing
5 changed files
with
83 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-FileCopyrightText: 2022 Comcast Cable Communications Management, LLC | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package wrpcontext | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type contextContentsKey struct{} | ||
|
||
// Set provides a standard way to add a wrp message to a context.Context. This supports not only wrp.Message | ||
// but also all the other message types, such as wrp.SimpleRequestResponse | ||
func SetContents(ctx context.Context, b []byte) context.Context { | ||
return context.WithValue(ctx, contextContentsKey{}, b) | ||
} | ||
|
||
// Get a message from a context and return it as type T | ||
func GetContents(ctx context.Context) ([]byte, bool) { | ||
src := ctx.Value(contextContentsKey{}) | ||
if src == nil { | ||
return []byte{}, false | ||
} | ||
|
||
return get[[]byte](ctx, src) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-FileCopyrightText: 2022 Comcast Cable Communications Management, LLC | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package wrpcontext | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/xmidt-org/wrp-go/v3" | ||
) | ||
|
||
type contextWRPMessageKey struct{} | ||
|
||
// Set provides a standard way to add a wrp message to a context.Context. This supports not only wrp.Message | ||
// but also all the other message types, such as wrp.SimpleRequestResponse | ||
func SetMessage(ctx context.Context, msg any) context.Context { | ||
return context.WithValue(ctx, contextWRPMessageKey{}, msg) | ||
} | ||
|
||
// Get a message from a context and return it as type T | ||
func GetMessage(ctx context.Context) (*wrp.Message, bool) { | ||
src := ctx.Value(contextWRPMessageKey{}) | ||
if src == nil { | ||
return nil, false | ||
} | ||
|
||
return get[*wrp.Message](ctx, src) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters