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

Decoders/encoders for Network Addres Types #68

Closed
rikvdkleij opened this issue Feb 3, 2017 · 16 comments
Closed

Decoders/encoders for Network Addres Types #68

rikvdkleij opened this issue Feb 3, 2017 · 16 comments

Comments

@rikvdkleij
Copy link
Contributor

I can not find encoders and decoders for network address types as inet and cidr. Is there specific reason they are missing?

@nikita-volkov
Copy link
Owner

Simply no research has been commenced on the according binary codecs. You can take it on if you want. The according PRs will be merged.

@rikvdkleij
Copy link
Contributor Author

I will give it a try..

I just cloned project and used stack init to create stack.yaml. Stack choose resolver nightly-2017-02-03 (so GHC 8.0.2) . Build and run the tests. Some of the tests are failing:

  Unknown:                                             FAIL
    expected: Right True
     but got: Left (SessionError (ResultError (ServerError "3F000" "no schema has been selected to create in" Nothing Nothing)))
  Enum:                                                FAIL
    expected: Right "ok"
     but got: Left (SessionError (ResultError (ServerError "3F000" "no schema has been selected to create in" Nothing Nothing)))
  The same prepared statement used on different types: OK
  Affected rows counting:                              FAIL
    expected: Right 100
     but got: Left (SessionError (ResultError (ServerError "3F000" "no schema has been selected to create in" Nothing Nothing)))
  Result of an auto-incremented column:                FAIL
    expected: Right (1,2)
     but got: Left (SessionError (ResultError (ServerError "3F000" "no schema has been selected to create in" Nothing Nothing)))

Do I have to create local database?

@nikita-volkov
Copy link
Owner

nikita-volkov commented Feb 3, 2017

No. It seems like you're missing the default "postgres" schema. The tests assume that you have it. It doesn't matter what the contents of it are though.

@rikvdkleij
Copy link
Contributor Author

I have default postgres schema. Also, not all tests are failing.

@nikita-volkov
Copy link
Owner

This is definitely due to your local Postgres configuration, the tests run fine on the default Travis configuration. I think the following should help with your issue: http://dba.stackexchange.com/q/106057/52225.

Also please notice that all Hasql codecs are actually implemented in a separate project: https://github.com/nikita-volkov/postgresql-binary. Hasql merely provides wrappers.

@rikvdkleij
Copy link
Contributor Author

rikvdkleij commented Feb 8, 2017

Yes, it was my local Postgres configuration.

The roundtrip test is working for the inet datatype. I will sent PR if it's completely done.

@rikvdkleij
Copy link
Contributor Author

@nikita-volkov
What do you think:

  • Depend on network package for HostAddress but it's just a type alias for Word32? network package does not have type for netmask;
  • Do not depend on other package, just use tuple of 4 Word8's for IP4 and Word8 for netmask;
  • Depend on iproute package which has AddrRange IPv4?

Similar for IP6.

@nikita-volkov
Copy link
Owner

Do not depend on other package, just use tuple of 4 Word8's for IP4 and Word8 for netmask;

Since there's no standard package for those types, it's best to have the neutral option. Hence is my vote for this.

@rikvdkleij
Copy link
Contributor Author

rikvdkleij commented Feb 9, 2017

Since there's no standard package for those types, it's best to have the neutral option. Hence is my vote for this.

I agree.

Another question. I'm almost there 😄
For IPv6 I have to serialize Word16s to list. ByteString.pack can only serialize Word8. So I looked around on hackage and I found package binary. Do you agree with using this library?

@rikvdkleij
Copy link
Contributor Author

rikvdkleij commented Feb 9, 2017

Hmm, when I use LazyByteString the tests fail...

Using lazy byte strings ('binary' package does not have strict version): not enough writing and reading bytes

@rikvdkleij
Copy link
Contributor Author

Nevermind, I will try another solution, maybe with 'cereal' package.

@nikita-volkov
Copy link
Owner

No. There's no need for either of those packages. All the tools you need are in "bytestring".

Please look at the implementations of other codecs in https://github.com/nikita-volkov/postgresql-binary.

@rikvdkleij
Copy link
Contributor Author

rikvdkleij commented Feb 10, 2017

I have it working for IP4 with and without netmask. Tests are passing.

Point is, for IP6 I need function to go from [Word16] to ByteString.

@nikita-volkov
Copy link
Owner

Can be this or this. You'll have to detect, which endianness they use in Postgres, with tests.

@rikvdkleij
Copy link
Contributor Author

Thanks for your tip.

I'm making progress again, hopefully I see all tests passing soon.

@rikvdkleij
Copy link
Contributor Author

It's done 😄

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

No branches or pull requests

2 participants