collation.go 764 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package mssql
  2. import (
  3. "encoding/binary"
  4. "io"
  5. )
  6. // http://msdn.microsoft.com/en-us/library/dd340437.aspx
  7. type collation struct {
  8. lcidAndFlags uint32
  9. sortId uint8
  10. }
  11. func (c collation) getLcid() uint32 {
  12. return c.lcidAndFlags & 0x000fffff
  13. }
  14. func (c collation) getFlags() uint32 {
  15. return (c.lcidAndFlags & 0x0ff00000) >> 20
  16. }
  17. func (c collation) getVersion() uint32 {
  18. return (c.lcidAndFlags & 0xf0000000) >> 28
  19. }
  20. func readCollation(r *tdsBuffer) (res collation) {
  21. res.lcidAndFlags = r.uint32()
  22. res.sortId = r.byte()
  23. return
  24. }
  25. func writeCollation(w io.Writer, col collation) (err error) {
  26. if err = binary.Write(w, binary.LittleEndian, col.lcidAndFlags); err != nil {
  27. return
  28. }
  29. err = binary.Write(w, binary.LittleEndian, col.sortId)
  30. return
  31. }