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

GH-73 Add context modifier to CoapRequest #74

Merged
merged 1 commit into from
Nov 22, 2023
Merged

Conversation

szysas
Copy link
Collaborator

@szysas szysas commented Nov 20, 2023

No description provided.

@szysas szysas requested a review from sbernard31 November 20, 2023 18:58
@szysas
Copy link
Collaborator Author

szysas commented Nov 20, 2023

@sbernard31 would that work for you? Very simple addition to support context modifier.

@sbernard31
Copy link
Collaborator

It could do the job but during this conversation (#68 (comment)), I understood that with*** method was mainly temporary solution.

So maybe we can directly go with a more future proof changes ?
Like :

coapRequest.modify()
           .context(ctx -> ctx.with(key,value))
           .build();

Where modify will be :

public final class CoapRequest {
  // ...

  public CoapRequest.Builer modify() {
    return new CoapRequest.Builer(this);
  }

  // ...

  public static class Builder {
    private Builder(CoapRequest coapRequest) {
            this.method = coapRequest.method;
            this.options = CoapOptionsBuilder.from(coapRequest.options);
            ... 
            ...
            this. transContext = coapRequest.transContext; 
    }
  }
}

I mean we add this modify method but you keep the existing with** methods and you will deprecated/remove it when you think this will be the right moment.

@szysas szysas force-pushed the request-builder-context branch from 73909ef to 090788a Compare November 21, 2023 18:55
@szysas
Copy link
Collaborator Author

szysas commented Nov 21, 2023

You're right, going directly to .modify() function is a better option.
How about now?

@sbernard31
Copy link
Collaborator

Yep it sounds good. 👍

So to add a entry in transport context of a request, this will look like :

coapRequest.modify()
           .context(key,value)
           .build();

Do we need to add this methods to builder ?

public Builder context(Consumer<TransportContext> contextFunc) {
    contextFunc.apply(transport);
    return this;
}

That was my initial idea but thinking a bit more about it I think this is not really needed. Any opinion ?

@szysas
Copy link
Collaborator Author

szysas commented Nov 22, 2023

I don't think it is needed, anyway we can always add it later.

@szysas szysas merged commit ef8809f into master Nov 22, 2023
4 checks passed
@szysas szysas deleted the request-builder-context branch November 22, 2023 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants