AppendFCtrl appends encoded msg to dst.
(dst []byte, msg *ttnpb.FCtrl, isUplink bool, fOptsLen uint8)
| 53 | |
| 54 | // AppendFCtrl appends encoded msg to dst. |
| 55 | func AppendFCtrl(dst []byte, msg *ttnpb.FCtrl, isUplink bool, fOptsLen uint8) ([]byte, error) { |
| 56 | if fOptsLen > 15 { |
| 57 | return nil, errExpectedLowerOrEqual("FOptsLen", 15)(fOptsLen) |
| 58 | } |
| 59 | b := fOptsLen |
| 60 | if msg.GetAdr() { |
| 61 | b |= 1 << 7 |
| 62 | } |
| 63 | if msg.GetAck() { |
| 64 | b |= 1 << 5 |
| 65 | } |
| 66 | if isUplink { |
| 67 | if msg.GetAdrAckReq() { |
| 68 | b |= 1 << 6 |
| 69 | } |
| 70 | if msg.GetClassB() { |
| 71 | b |= 1 << 4 |
| 72 | } |
| 73 | } else { |
| 74 | if msg.GetFPending() { |
| 75 | b |= 1 << 4 |
| 76 | } |
| 77 | } |
| 78 | return append(dst, b), nil |
| 79 | } |
| 80 | |
| 81 | // UnmarshalFCtrl unmarshals b into msg. |
| 82 | func UnmarshalFCtrl(b []byte, msg *ttnpb.FCtrl, isUplink bool) error { |